C++ Communications between two classes

Hi guys,

do anyone know, how can I set a variable of a class outside this class?

I have worked through the tutorial “First Person Shooter C++ Tutorial” And now I want to try experimenting…

So I have the class:
class FPSPROJECT_API AFPSHUD : public AHUD
with a public bool.

How can I change this public bool outside?

I am very confused 8(

Can somebody help me ?

Obviously you will need find pointer to object that you want to communicate, study API reference:

Theres also offline version of it in /Engine/Documentation/CHM which i think it easier to work with. Lot of classes got pointers to various objects, so check AHUD:

For example if your bool is in pawn (let say AFPSPawn) possesed by player controller you can do something like this from AHUD:

((AFPSPawn*)PlayerOwner->GetPawn())->bSomeBool=true;

since you didn’t tell where you got your bool i can’t directly help you how to get set that bool in your case

If it’s not hud but some random custom class you’ve created then you just use c++ basics. There are no special requirements by UE for general c++. As soon as you use object of that class type you can always get access to its public variables.

For hud case: there are multiple ways to get it. You have HUD assigned to your Player Controller. You should just get a pointer to proper PC object and get its HUD like this (as example):

AFPSHUD* MyHUD = Cast<AFPSHUD>(()->GetFirstPlayerController()->GetHUD());
MyHUD->MyBooleanVariable = true;

or using Kismet functions. Or getting player controllers’ list iterator. You choose the most convenient way.

Thank you very much!! :smiley: :smiley: :smiley: