So as far as I know, Unreal has the following pointer types:
- TObjectPtr: stores a hard reference to a UObject and becomes auto-nulled when the object is explicitly destroyed.
- TWeakObjectPtr: stores a weak reference to a UObject and will always know when an object has been destroyed.
- TSoftObjectPtr: stores a path reference to a UObject Asset and can cache it into a TWeakObjectPtr.
- TLazyObjectPtr: very similar to TSoftObjectPtr but stores via a genuine unique UUID (which is mostly not needed).
What I’m looking for is a type of Soft Reference that when loaded, converts into a genuine hard reference. Think of a TSoftObjectPtr but using a TObjectPtr as its backing cache structure as opposed to a TWeakObjectPtr.
To me, this sounds like what a Lazy Object Ptr should do and feel like it’s something that must be in the engine somewhere since it doesn’t seem like it’s a niche thing.
The use case for this is for lazily loading assets at runtime but then keeping them loaded for as long as I say so.
It seems silly that every time I do this, I have to make two separate variables, the TSoftObjectPtr to reference the asset and the TObjectPtr to keep it loaded.
Does anyone know if the engine does actually have this behaviour?
I was thinking of making my own type that would do this but then the trouble is making my templated struct work with UProperties.