Create numeric uint32 ID for Assets

I am currently looking for a way to create a stable ID (uint32) for Unreal assets.
The assets have the same type, e.g. deriver from the same UObject based class.
Has anyone already done something similar?

The uint32 ID is used for network synchronization and cannot be represented as FName.
It should be possible to convert the asset from and to its uint32 ID representation.

I looked at FPrimaryAssetId, but it doesn’t support this use case, since it is based on the name of the asset. The asset name should be user-definable.
Therefore, something like numeric naming of assets is not an option.

It would probably be helpful to explain what you need this for. ie Why do you want a stable uint32 id for unreal assets?

My main use case is that I have an external server that sends the client which actor to spawn in the world and where. There are many different types of actors.
Right now I address actors with a numeric name, but that probably won’t work properly in cooked builds and I want to be able to name actors with a custom name again.
Since the actor classes are known in advance, I want to create a common way for the external server and client to exchange the actor class without sending the whole soft object path.

Well why don’t you create a blueprint in the editor with an array of actor subclasses (ie TArray<TSubclassOf<AActor>>), and then your unique id is the index of the actor subclass in that array. (You can also build a reverse lookup table TMap<TSubclassOf<AActor>, uint32> from the array while bringing the world up for play if you need the reverse lookup to be fast too.)

1 Like