UObject get deleted just after being created

Hey I can see a few issues with your code, garbage collection is not the problem as far as I can tell.

1. Use are using NewOjbect<>() incorrectly.

The correct use for you is:

LifeResource = NewObject<UResource>(this, UResource::StaticClass());

You need this so the object knows which world is belongs to and who it’s owner is. UResource::StaticClass() is the actual class you want to instantiate.

2. If that doesn’t completely fix your problem, try moving the NewObject<>() code to BeginPlay() or PostInitProperties()

The constructor in Unreal is a bit odd, since it is called by the editor to create the Class Default Object (CDO).

I didn’t read the rest of your code, so let me know if there are any more problems.