[GC] Object variables collected prematurely
Problem - Objects created in actor constructor and stored in TMap are getting variables collected (set to random) after start of the game.
Details In ATestActor I create 500 UTestObjects. Each of them has variable id=0 defined in UTestObject header. In "Begin Play" I go through whole map printing out ids of each UTestObject and getting values like -842150451 etc.
If I do the printing in constructor, it works and outputs 0 for each object.
Garbage collector should not collect those since I have pointers to them stored.
I am sure I am missing something trivial,
Thanks for any help,
//Simple TestObject header
asked Dec 04 '16 at 05:29 PM in C++ Programming
Answer - TMap and other containers has to be declared with UPROPERTY() in the header file. More info here https://wiki.unrealengine.com/Garbage_Collection_%26_Dynamic_Memory_Allocation
answered Dec 04 '16 at 06:07 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here