Algosyntax Logo

UE5 Runtime Dynamic Objects And FSoftObjectPath

Advertisement

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

Consider investing in some of our plugins. They might save you some time.  Also helps supports these tutorials.

Instantly get access to our plugins like Blender Curves Importer and UMG Cinematics and more when  you support us on Patreon!

 Join Us On Discord For More Daily Tips!