Persistent unique identifier for components

This question is only about the context of a single world/level.

Using world partition, Actors are loaded in and out as needed. Their name acts as a unique identifier which remains the same across all loads/unloads of the same actor.

Is there a way to get a similar identifier for scene and actor components?

One option is to use the owning actor name and the component name as they are unique for first level components:

// Get unique uint32 from unique FString
GetTypeHash(GetOwner()->GetName() + GetName());

e.g. Actor1234 -> CoinComponent and Actor1234 -> CoinComponent1 are unique.

However, this would not work for nested components as the names may clash across hierarchies.

e.g. Actor1234 -> CoinComponent -> Collider and Actor1234 -> CoinComponent1 -> Collider would lead to two instances of Actor1234Collider

UObjectBase.h has the following:

/** 
 * Returns the unique ID of the object...these are reused so it is only unique while the object is alive.
 * Useful as a tag.
**/
FORCEINLINE uint32 GetUniqueID() const
{
	return (uint32)InternalIndex;
}

The comment seems to suggest that this may change as the object is loaded in and out (only unique while the object is alive). Does this mean that it is not guaranteed to be the same for the same component being handled by the world partition?

EDIT: This does not persist as noted by the comment and so can’t be used.

Is there a way to get unique names or IDs for components that persist across loading and unloading a single level?

The aim is to use this ID to update a per-world database with which actor components have been hit/collected/destroyed etc.

The ID does not have to be the same between loads of the same level but must be unique during the lifetime of a single level.

GetFullName() returns the concatenated name of the component hierarchy which is persistent across world partition loads:

// Get unique uint32 from unique FString
GetTypeHash(GetFullName());

This can be called in BeginPlay() and does a mapping like:

/Memory/UEDPIE_0_DZXDIA80NPY1ZLLGJI1HQDL72.LevelName:PersistentLevel.Actor_UAID_80A9973744BC859B02_1789382591.ComponentLevelA.ComponentLevelB → 2217610456

1 Like