Is it safe to do something like the following ( don’t ask why :p) :
TSharedPtr<UObject>(NewObject<MyObjectClass>(SomeOwner));
or are smart pointers only for non uobjects and every Uobject derived class should be maintained exclusively only by reflection system?
1 Like
There is a TWeakObjPtr you can use to store a weak uobject reference, but otherwise have to go through the UPROPERTY system.
No, don’t do that.
We have TWeakObjectPtr<> for that case.
I don’t know if that TSharedPtr<UObject> would even compile. When I tried some year ago, Unreal just said “no!”
Balgy
(Balgy)
4
Unreal uses a garbage collection system to do its memory management, so you can also take advantage of that.
If there is a fundamental need for your object to not be destroyed, there is a way to add an object to GC’s root set: https://api.unrealengine.com/INT/API…oot/index.html