Warning for deprecated type with 5.5 ?

Since updating to 5.5 I get this warning when compiling my project with UE5.5 (upgraded from 5.4)

warning C4996: ‘TSoftObjectPtr < UTexture2D > ::TSoftObjectPtr’: Constructing TSoftObjectPtr from an incompatible pointer type has been deprecated. Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.

Also for a custom type:
TSoftObjectPtr< MyBaseDataAsset >::TSoftObjectPtr’: Constructing TSoftObjectPtr from an incompatible pointer type has been deprecated. Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.

Same with Visual Studio 2022 and JetBrains Rider.
Any ideas?

I think I found the reason and a solution, so it might help someone else if they stumble upon this.
It seems in 5.5 some implicit casts have been deprecated.
So code like:

TMap<TSoftObjectPtr<UTexture2D>, FName> Found;
Found.Add(TSoftObjectPtr(a.GetAsset()), a.AssetName);

That worked before, as GetAsset returning UObject* was passing, now issues a warning for deprecation.
The solution I used is to explicitly cast.

Found.Add(TSoftObjectPtr(static_cast<UTexture2D*>(a.GetAsset())), a.AssetName);

If anyone has a different/better idea I’m opened to suggestions.

1 Like

in cases where i saw this,

where the following generates same warning as OP

USTRUCT(BlueprintType)
struct FSomeData {
...
	UPROPERTY()
	TSoftObjectPtr<UObject> Asset;
}

and assigning a value to this, that was using const UObject* Asset… the const was throwing things off.

so, instead using const inside the TSoftObjectPtr template declaration as follows

USTRUCT(BlueprintType)
struct FSomeData {
...
	UPROPERTY()
	TSoftObjectPtr<const UObject> Asset;
}

fixed the warning

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