TSoftClassPtr is null after each UE restart

Hey guys,
I have a developer settings class that I made, which contains a UDataAsset which holds an array of actors.
Each time I relaunch the editor, those references are null.
The only solution is to delete the array and re assigned every time.
Can someone explain what’s going on here?

The data asset:

class USpawnerDataInfo : public UDataAsset
{
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere)
	TArray<TSoftClassPtr<AActor>> ActorsList;
};

The developer settings:

UCLASS(Config = Game, defaultconfig, meta = (DisplayName = "Spawner Settings"))
class USpawnerSettings : public UDeveloperSettings
{
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, Config)
	TSoftObjectPtr<USpawnerDataInfo> DataInfo;
};

A debug:

Isn’t that exactly the expected behavior of a soft object ptr?
If it’s the object ptr that’s null (rather than the class ptr) then you need to actually load it to make it non-null.

jwatte is right you need to load the soft pointer otherwise it’s null (that is why it saves memory)

Try something like this

void USpawnerSettings::Load(){
	FSoftObjectPath AssetData  = DataInfo.ToSoftObjectPath();
	if (AssetData.IsValid()) {				
		USpawnerDataInfo * LoadedAsset = Cast<USpawnerDataInfo>(AssetData.TryLoad());
	};
}

LoadedAsset should be the retrieved asset from the soft pointer.

I know it’s the point of a soft pointer.
But that’s confusing me becuase there’s some TSoftClassPtr that shows a valid memory address on debug, and some that aren’t.
Which I didn’t load them. Any at all.

Maybe that’s the request behavior but I can’t understand why.

Perhaps the valid ones have already been loaded into memory elsewhere?

1 Like

Yep, it was initiated else where that why it showed be it has an address.
And reason I thought it was null (or any problem) that’s because I tried printing the name of the soft class using GetName which cause a null exception.

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