How to properly package FSoftObjectPath references

Hi, here’s one I’ve been trying to figure out for days.

In our code we have a few FSoftObjectPath based references. Since this is just a string path reference it doesn’t ensure it gets packaged.

Now of course I could make all those hard references (either by putting some dummy instances in the level, or anywhere in the blueprints), but the problem with that is that then it gets loaded right away so the levels then take longer to load. We’re using soft references for a reason though, for instances for stuff that is not needed every time you run the app, but only sometimes and can be thus loaded later.

At this point I use +DirectoriesToAlwaysCook to include all the assets, but that’s not very handy as it requires very precise folder sorting, if you don’t want to include stuff that isn’t used at runtime by the packaged app.

My research on the topic shows that PrimaryAssetLabel is the thing I should probably use, but I haven’t been able to successfully set it up to do what I want. The documentation is rather vague.

Assume I want to just include two specific assets (in reality there’s more of them, but once I am able to set it up for some, it will be easy to set it up for the rest). One is a LevelSequence and one is a Movie Pipeline Queue asset:

[Image Removed]

and another one is a Level Variant Sets asset.

I tried creating a PrimaryAssetLabel, set the cook rule to Always cook and then added those asset references as Explicit Assets. Like this for example:

[Image Removed]

It wouldn’t however add it to the package. I wasnt’ able to load it and also couldn’t see it among the cooked assets.

I figured that maybe it wasn’t able to find the label so I also tried messing around with the Asset Manager settings in the Project settings, but again, no luck.

Can you please advise?

Regards

Jan

Hi [mention removed]​,

PrimaryAssetLabel is a perfect way to go. In the PrimaryAssetLabel you can specify the exact assets you want to cook and they should get cooked and ready to use in a packaged application. From the configuration you have, both assets should get cokked, but if you try to access the PrimaryAssetLabel it will fail. For accessing it, you need to also enable the IsRuntimeLabel flag.

Then in the code, you can try to load the asset directly and see if it is able to do it. I’ll let you the code I’ve used as a SoftObject so you can test it yourself. In my case I’ve used two assets that are not being added to any level or either hard referenced by another blueprint.

The PrimaryAssetLabel:

[Image Removed]

The code to load it at runtime:

`void ATPP5_6Character::BeginPlay()
{
Super::BeginPlay();

FSoftObjectPath AssetPath(TEXT(“/Game/CookCase/LS_MyLevelSequence.LS_MyLevelSequence”));
UObject* LoadedAsset = AssetPath.TryLoad();

if (LoadedAsset)
{
GEngine->AddOnScreenDebugMessage(-1, 30.f, FColor::Red, FString(“Asset successfully loaded at runtime.”));
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 30.f, FColor::Red, FString(“Asset NOT loaded at runtime.”));
}
}`

In my case if I removed the assets from the PrimaryLabelAsset, I was not able to load them, so in my case the PrimaryLabelAsset is the responsible on making know the cooking process to also cook the ExplicitAssets.

Let me know if those changes worked for you. If not if you could make a repro project or give a bit more of information could be a great help.

Best,

Joan

Hi, sorry for the delay.

I’ve been on paternity leave now for a while and it took me a while to get over the heap of emails to get to this one…

Anyway, yes I think the problem was I’ve forgotten to set the IsRuntimeFlag. On top of that, I think there was a second issue that it could only find the PrimaryAssetLabel if it was in the Content root. When I had it in a subfolder, it would completely ignore it.

Thanks for your help.

Jan!