Download

Is it safe to use sharedptr to act as Uobject hard reference?

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?

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!”

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