UE5 Runtime Dynamic Objects And FSoftObjectPath

A Quick tip on FSoftObjectPath in Unreal Engine: Sometimes you may need FSoftObjectPaths for “Assets” created at runtime and thus only available in memory and not on disk. I placed “Asset” in quotes cause “Asset” is usually used to refer to a UObject that is also serialized to disk. 
Anyway, FSoftObjectPath has a constructor that takes in a UObject. So just do this:

				
					UObject* MyObject=NewObject<UObject>();

FSoftObjectPath MyObjectPath(MyObject);

				
			

NB: Things to keep in mind:

If you’re going to pass your FSoftObjectPath to something, just know that its simply a WeakPointer, so you need to hold “MyObject” as a UProperty() so that it persists throughout the usage lifetime of MyObjectPath. 
Just something to think about it, if GC collects the Object, the ObjectPath is still pointing to deleted objects….

5/5

Gamechanger plugin for notehighway rhythm games and music visualizers

5/5

Add Text and 2D UMG widgets to Level Sequences

5/5

Simplify your Plugin Development with the Unreal Projects Manager

5/5

Learn how to create unreal engine plugins from scratch and sell them on Fab.com.