Die to Survive - Railshooter

In BP you pull a pin of a soft object / soft class ptr and type “load” which gives you the synchronous option, returning an object which you need to cast to what you need. I believe that outside of functions in the event graph BP also have the async option. BP functions don’t support async nodes sadly but the event graph does. If you write the logic in c++ yourself to load those ptrs you can expose a soft variable to BP users, shouldn’t be an issue then for marketplace users to use if they can’t do programming.

Async loading in c++ is done like this:

// StreamingHandle
// SomeSoftPtr
TWeakObjectPtr<USomeClass> WeakThis(this);
StreamingHandle = UAssetManager::GetStreamableManager().RequestAsyncLoad(SomeSoftPtr.ToSoftObjectPath(),[WeakThis]() {
	USomeClass* StrongThis = WeakThis.Get();
	if (IsValid(StrongThis)) {
		// Has finished loading async, get the content with // StrongThis->SomeSoftPtr.Get()
		// Do stuff with the retrieved content here.
	}
}, FStreamableManager::AsyncLoadHighPriority);

/* 
* Binding can only be done when async loading is in progress.
*/
if (StreamingHandle.IsValid()) {

	// On cancelled

	FStreamableDelegate CancelDelegate;
	CancelDelegate.BindLambda([WeakThis]() {
		// USomeClass* StrongThis = WeakThis.Get();
		// Do something with this if you want.
	});
	StreamingHandle->BindCancelDelegate(CancelDelegate);

	// On updated

	FStreamableUpdateDelegate UpdateDelegate;
	UpdateDelegate.BindLambda([WeakThis](TSharedRef<FStreamableHandle> InHandle) {
		// USomeClass* StrongThis = WeakThis.Get();
		// Do something with this if you want.
	});
	StreamingHandle->BindUpdateDelegate(UpdateDelegate);
}
1 Like