How to get value from another class member?

then I dont know what you mean. I added the grabber component in bp_player as component

Then in code like in this post

void UTriggerComponent::BeginPlay()
{
    Super::BeginPlay();

    APawn* Player = UGameplayStatics::GetPawn(this, 0);
    Grabber = Player->FindComponentByClass<UGrabber>();
}
1 Like

Thanks @DanM small edit to use GetPlayerPawn and it work great.

Now just for learning is there a way in C++ without using FindComponentByClass and UGameplayStatics.GetPlayerPawn ? in @ VeryClumsySloth solution ?. In his solution Grabber always nullptr

So I tried to use new operator in begin play but then I found this great topic

I will do some reading and try to use NewObject

Like I said earlier, that’s not possible. Also he grabber is already dynamically allocated and newing your bool sn’t going to change anything about how you get it.

You could make the member on the grabber static. Static member variables are essentially global variables.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

This topic was automatically closed after 30 days. New replies are no longer allowed.

Privacy & Terms