Change variable from one file in another


I think this is a pretty standard beginner-question:

I have two classes, first my GameCharacter, and second my Inventory, which extends from HUD. I want to set the bool “bIsInventoryOpen” to true/false, when pressing I. Unfortunately though, while I have to set the variable in my GameCharacter, I need to check whether it’s true in the Inventory-class.

Now either I have to do this in a completely different way I don’t know of, or I have to find a way to change the variable “globally”.

I keep reading about Interfaces, but I can’t find out how to use them, or what they actually are.

After hours of searching and experimenting however I haven’t found a way to get this to work. I hope you can help me getting this to work. I’m still just starting to work with UE4, and even though I know the basics of C++, UE4 C++ gives me a lot of trouble, and I apologize if this is an obvious thing.

Thank you in advance! :slight_smile:

I’m assuming you are attaching the HUD as a component to your character class? You could write a public function on your Inventory class.

bool isInventoryOpen()
return bIsInventoryOpen;

Then just call it by using


Hope that helps.

Thank you for your answer :smiley:

Quite honestly I ddidn’t. I just created the class, and tried what I wrote above. That’s as far as I’ve got.

I so far couldn’t quite understand why I should use components, what they actually are, and how to use them.

“PlayerCharacterPointer->GetHUD()->isInventoryOpen()” could you explain this a little more (So a noob like me can understand it :D)? Especially the pointer-part.