TSoftObjectPtr is pointing to null instead of valid file path

Hi,
So I am trying to replicate the LyraSampleGame in my project but I am having some troubles with the LyraAssetManager code.
In the LyraAssetManager.h file, I see that LyraGameDataPath is declared as a TSoftObjectPtr of LyraGameData.h and that it is only used once in the entire solution by LyraAssetManager.cpp

const ULyraGameData& ULyraAssetManager::GetGameData()
{
// LyraGameDataPath has this value here  '/Game/DefaultGameData.DefaultGameData'
	return GetOrLoadTypedGameData<ULyraGameData>(LyraGameDataPath);
}

When I was debugging from the code snippet above, I see that LyraGameDataPath contains the value ā€˜/Game/DefaultGameData.DefaultGameData’, however in my project LyraGameDataPath is null instead.

I have also checked my DefaultGame.ini file and under [/Script/Engine.AssetManagerSettings] LyraGameData is present there in my project as well.

What am I missing that is causing this differences? Please help, I have been stuck at this for two weeks now and I still could not solve it.

I can’t help with Lyra specifically, as I’m not a Lyra user, but I can try.
You say this TSoftObjectPtr is only accessed once in the entire solution (assuming your own code as well). Could it be one of your blueprints is storing its own value and loading that instead of the value set in the ini? This is a very common issue with blueprints…

All this is C++ code, the LyraGameDataPath is (to my understanding) referring to another C++ file named ā€œLyraGameDataā€.

There is a blueprint class derived from LyraGameData named DefaultGameData but I thought only Blueprint classes can use code from C++ classes and not the other way around?

The AssetManager is declaring the LyraGameDataPath using this code snippet:

UPROPERTY(Config)
	TSoftObjectPtr<ULyraGameData> LyraGameDataPath;
//LyraGameDataPath will contain this value ā€˜/Game/DefaultGameData.DefaultGameData’

But I do not understand where does Lyra gets the value from.

Thanks for your reply btw. This is the code for the LyraGameData .h and .cpp file, fyi since you said you’re not a Lyra user.

LyraGameData.h

// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "Engine/DataAsset.h"
#include "UObject/SoftObjectPtr.h"
#include "UObject/UObjectGlobals.h"

#include "LyraGameData.generated.h"

class UGameplayEffect;
class UObject;

/**
 * ULyraGameData
 *
 *	Non-mutable data asset that contains global game data.
 */
UCLASS(BlueprintType, Const, Meta = (DisplayName = "Lyra Game Data", ShortTooltip = "Data asset containing global game data."))
class ULyraGameData : public UPrimaryDataAsset
{
	GENERATED_BODY()

public:

	ULyraGameData();

	// Returns the loaded game data.
	static const ULyraGameData& Get();

public:

	// Gameplay effect used to apply damage.  Uses SetByCaller for the damage magnitude.
	UPROPERTY(EditDefaultsOnly, Category = "Default Gameplay Effects", meta = (DisplayName = "Damage Gameplay Effect (SetByCaller)"))
	TSoftClassPtr<UGameplayEffect> DamageGameplayEffect_SetByCaller;

	// Gameplay effect used to apply healing.  Uses SetByCaller for the healing magnitude.
	UPROPERTY(EditDefaultsOnly, Category = "Default Gameplay Effects", meta = (DisplayName = "Heal Gameplay Effect (SetByCaller)"))
	TSoftClassPtr<UGameplayEffect> HealGameplayEffect_SetByCaller;

	// Gameplay effect used to add and remove dynamic tags.
	UPROPERTY(EditDefaultsOnly, Category = "Default Gameplay Effects")
	TSoftClassPtr<UGameplayEffect> DynamicTagGameplayEffect;
};

LyraGameData.cpp

// Copyright Epic Games, Inc. All Rights Reserved.

#include "LyraGameData.h"
#include "LyraAssetManager.h"

#include UE_INLINE_GENERATED_CPP_BY_NAME(LyraGameData)

ULyraGameData::ULyraGameData()
{
}

const ULyraGameData& ULyraGameData::ULyraGameData::Get()
{
	return ULyraAssetManager::Get().GetGameData();
}

The specifier Config is:

Property Specifiers | Unreal Engine Documentation

This property will be made configurable. The current value can be saved to the .ini file associated with the class and will be loaded when created. Cannot be given a value in default properties. Implies BlueprintReadOnly.

So one could assume this property is never overriden by a blueprint. I’m a bit skeptical though. You could try to create a new blueprint class dericing from LyraGameData, use that and see if the problem persists. Blueprints can override and store values from their c++ parent class. More than often data gets stuck in there.

This is it! I figured it out, Lyra specify the LyraGameDataPath thru DefaultGame.ini. Thanks Roy for helping me figure this out.

I managed to get the path to be ā€˜seen’ by my C++ code but it is still not loading the GameData correctly (I still get an error).
Error message:

Fatal error: [File:\..\CPP_AssetManager.cpp] [Line: 272] Failed to load GameData asset at /Game/Content/DefaultGameData.DefaultGameData. Type CPP_GameData. This is not recoverable and likely means you do not have the correct data to run <My Project Name>.

Side note, could it be due to this? I notice that in Lyra the DefaultGameData blueprint has a pink-redish line while in my Content Browser, my DefaultGameData is blue. I just create a blueprint class based on my C++ GameData file, is that not the way to create it?

Pic for references:
From Lyra:
image

From my project:
image

Coloring is based on the datatype, blue normally being a UObject or AActor based class. Are you certain your CPP_GameData class derives from LyraGame.LyraGameData? It doesn’t seem to be a data asset of proper type.

My CPP_GameData has the same code as the LyraGameData code above, but the blueprint derived from it is blue instead of red.
Strange, is there a way to specify to Unreal that this is a data asset instead?

You should probably derive from LyraGameData.

Ah I need to create a Data Asset class and then reference the CPP_GameData C++ file instead of directly deriving a blueprint class from C++. That’s it I am able to run my project now. Thank you so much for your help.

I feel like this should have a warning by Unreal (for newbies like me) that when deriving Blueprint class from C++ DataAsset files, we should create a DataAsset Blueprint class in UE5 instead of directly right-clicking the C++ file and create a Blueprint class from there.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.