Download

[Super Beginner]How to access my Project Character

Hi there, I am working with the top down template and I want to modify the topdowncharacter cameraboom through the playercontroller, but I don’t know how to gain the reference to my project character from the playercontroller class.

You have to use the Cast to get your character variables from your player controller class.

How would i cast to get my character? The problem that I see is that my character has been created somewhere so now how do I get the reference from it.

hi danielsega, if you mean get the pawn you can get from this:
the easy way is include “GameStatic.h” in your class you want the reference

so you can call this



      APawn* myPawnCharacter = GameStatics::GetPlayerPawn(0) //with the index of the player, regular 0 works


if you have some custom pawn then you really need cast in this way:



     AMyCustomPawn* myCustomPawnCharacter = Cast<AMyCustomPawn>GameStatics::GetPlayerPawn(0); //almost the same just cast 


are another ways, buts this one is easy

Cheers!


AAtlasCharacter* const atlasChar = Cast<AAtlasCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));

Thanks for the help guys and some research, I managed to gain access to my costume character with the code above. Since I am new to unreal there still a concern. I am assuming that once Casted, I won’t need to delete the pointer manually later since I don’t see it on samples.

ohh hell yeah i forget is UGameStatics sorry about that, anyway if you use a lot a call for references you can use TSharedPtr<> this a smart ptr if you dont know when you must delete some pointer sharedptr doing for

Cheers