Download

Referencing assets for stand-alone game version

Hello.
I am packaging my game and after running it i can’t see game world.
In my “world spawner” class i am referencing assets this way:


FStringAssetReference tileGrass = "Blueprint'/Game/MyContent/BP_Sprites/grass.grass'";
FStringAssetReference tileSand = "Blueprint'/Game/MyContent/BP_Sprites/sand.sand'";
FStringAssetReference tileWater = "Blueprint'/Game/MyContent/BP_Sprites/water.water'";

StaticLoadObject(UObject::StaticClass(), nullptr, *tileGrass.ToString());
StaticLoadObject(UObject::StaticClass(), nullptr, *tileSand.ToString());
StaticLoadObject(UObject::StaticClass(), nullptr, *tileWater.ToString());

but looks like


tileToSpawn = tileGrass.ResolveObject();

is returning null so i can’t see my map.

The question is - how to reference assets for packaged version of game?
I tier with and without pak files option and both doesn’t work for me.

I think you need to call TryLoad on the reference.
tileToSpawn = Cast<UTileClass>(tileGrass.TryLoad());

I resolved this issue.
According to https://answers.unrealengine.com/questions/273278/fstringassetreferencetryload-failed-on-android-dev.html

i changed FStringAssetReference to FStringClassReference
and i am loading this objects using tileGrass.TryLoadClass<APaperSpriteActor>();

now my code looks like this:



//Reference to my resource
FStringClassReference tileGrass("Blueprint'/Game/MyContent/BP_Sprites/grass.grass_C'");

//Load it
tileGrass.TryLoadClass<APaperSpriteActor>();
UClass * tileToSpawn = nullptr;
tileToSpawn = tileGrass.ResolveClass();

//Spawn it
UWorld * const World = GetWorld();
APaperSpriteActor * spawnedObject = Cast<APaperSpriteActor>(World->SpawnActor(tileToSpawn, &SpawnLocation, new FRotator(0.0f, 0.0f, 0.0f)));