I assume you can’t declare classes like structs, so I’m wondering how do you safely initialize and destroy one? I’ve always used CreateDefaultSubObject/SpawnActor, neither of which is appropriate for a UDataAsset.
You can in with normal C++ class, but not UObjects, they exclusivly can be only hold as pointer and you can use “new”, “delete” or statically declare them (which you did) you need to use UE4 APIs to control “there existance”, since they haeavyly memoery managed. To create instance of UObject do this:
Also note, you can’t delete UObjects on demend, you also need to hold pointer to it in atleast 1 UPROPERTY() varable, the way UObjects work is that they automatically deleted by garbage collection when they are not referenced anywhere, you should also not circular refrence UObject without control because that might produce memory leak, always break the circle when objects are uneeded.
AActors are also UObjects but oyu use SpawnActor() insted of NewObject() also they can be deleted on demend
Ooh that clears up a lot, thank you!! So to be clear, I’m safe using a data asset as a kind of “Use and forget” data holder like I’ve described, and trusting Unreal to correctly GC it when it’s no longer being referenced anywhere?