Calling Functions in other Classes from UserWidget

hello everyone,

i know that my question is asked a lot in this forum and i read about it across several differen forums but still cant figure out how to do it. if you got a link that can solve my problem please let me know.

i have a userwidget and i am able to call a function in my class called APCameraPawn by casting the class like this:

CamPawn = Cast<APCameraPawn>(this);

i have intialized CamPawn in the header file like this:

APCameraPawn* CamPawn;

later i am able to call a function in the CameraPawn:

CamPawn->PlaceObject();

but changing a variable:

CamPawn->TabActive = true;

or calling another function from inside PlaceObject() always fails

should i use an Interface Class? i already tried but failed and would try again if thats the best way

i hope thats enough information. let me know if you want me to provide more code. thanks, steve

Regarding:

 CamPawn = Cast<APCameraPawn>(this);

If you’re calling this from a widget the cast won’t succeed because a widget (this) is not a APCameraPawn. So the call to PlaceObject() is most likely resulting in a null reference exception (CamPawn is nullptr).

You need to actually find a reference to your pawn, e.g. something like the following:

CamPawn = Cast<APCameraPawn>(GetOwningPlayer()->GetCharacter());