Get Reference to PlayerCharacter

Hi!

I have made a custom “MobClass” in an RPG game in c++, and I want to get a reference to the main player from within the mob class instance inside its “Tick(float DeltaTime)” function. Seemingly the mob instance and the player character instance are unrelated however. Is there any function of the sorts “GetMainPlayer()” that returns a pointer to the “AMyCharacter” object?

Any ideas?

Assuming your game is a single-player game, you can call UGameplayStatics::GetPlayerController(context, 0) and then call GetPawn() on that player controller to get the actual player character. (Or GetPawnOrSpectator() if you prefer.)

2 Likes

Thank you! :slight_smile: