I’m pretty new to UE4 C++. I’m on UE5. I’m coding a basic inventory system. I made a UInventorySlot (UObject) and a UInventoryComponent (UActorComponent). I just want to fill a TArray variable in the UInventoryComponent to init the inventory with empty slot. But it doesn’t work. At the end of the loop to init it, the TArray is full and correct, but when I try to access it via a function for example, the array is empty (num==0).
You may have a blueprint that already checkpointed the empty state.
Check if there’s a “revert to default” yellow arrow in the inventory property in a blueprint instance.
Or perhaps the warning comes from a different instance of an class, that hasn’t had the inventory added to it?
Have you tried to init your array with TArray.Init() to see if that works? I know thats not a solution to the problem but it might help you narrow down the issue.
Okay. What happens if you inspect the player objects / blueprints at runtime? Are the inventory slots still present?
How do you spawn your playerchars? If you havn’t tried already, try to drag one into the map and set that specific playerchars inventory to something and inspect it at runtime.
Okay I have more informations :
I did an initialization function and called it by an input, with the exact same loop. It worked.
So something happen after the beginplay and erase the pointers… But what ?
Edit :
I start to have something, I tested if the component was initialized during beginplay
And it isn’t. So I think the component initialization is done after beginplay and erase my own… Just need to know how to be sure BeginPlay is launch after init, or a way to detect when the init is done to launch my own.
Edit 2 :
No, the component init is only called if you want it and it’s before beginplay anyway… Seriously, there is nothing after beginplay… What the hell…
Edit 3 :
Nevermind, the problem seems to come from the Character class owning the component. I tested on a clean one, it works.