Why is my UObject being GC'd?
So i am trying to instantiate a UObject at runtime using NewObject like so:
I am marking the variable as a UPROPERTY, so as i understand it, the garbage collector should know when i am referencing this UObject:
The problem i have is after a certain amount of time, this UObject is being destroyed or marked as invalid and i get a crash at this point:
I cannot see any reason why this is. I have checked to make sure it is definitely the GC that is destroying the object, by creating the object with the MarkAsRootSet flag, which appears to fix this issue, but then the editor crashes when ever i try and exit the game as it cannot destroy the object.
If it helps at all, the UObject is being reference from a USTRUCT which is referenced by value from a UActorComponent like so:
It seems switching between GetTransientPackage() and this has fixed the issue
answered Feb 10 '17 at 01:27 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here