Download

How To Get Character Variables In A HUD Class

My custom character class ALifeCharacter has a variable (array) called ItemInventory that’s full of his inventory. In my custom AHUD class, AInventoryHUD, I need to get this variable and use it to foreach a bunch of Hitboxes onto the screen. I can do the latter, but I have no idea how to get the variable. Should be easy for some of you.

Thanks!

**Edit
I figured it out. In case anyone wants to know in the future, you can do it like so:


ALifeCharacter* MyCharacter = Cast<ALifeCharacter>(GetOwningPawn());
		
	TArray<class AInventory*> MyInventory = MyCharacter->GetCurrentInventory();

One tip: Check if the Pointer is not NULL before using it, see my thread: