Why would you Name Objects?

In a continuation of my previous question of Why do we need Player States A new question arises. What does “naming” an object do? I’ve seen it done in many C++ tutorials but no one explains why… Honestly I continued to do it just because they did it.

When we construct a UObject, UActorComponent, or spawn an Actor you can supply it a Name (FName to be exact). I never actually thought about it at first but then as I delved into the realm of replication and was looking at the UAbilitySystemComponent I noted a very interesting function that got me thinking that maybe the FName was for more than just decoration…

GetSubobjectsWithStableNamesForNetworking.

So the documentation on this is non-existant (and I don’t always have a copy of the UE4 source engine on me when I am researching these things). What does this do? Is there some mystical yet useful ability of naming your objects that deals with replication somehow? What other functionalists or benefits may exist for Naming your subobjects, components, and actors?

Names are unique identifiers for objects. Since they use FName, they have a string representation but are much faster for comparison than actual FStrings. They also have innate numbering mechanisms to ensure that any objects you don’t explicitly name (i.e.: placing a bunch of static meshes in a level, all will be named StatishMeshActor by default) still end up unique.

Documentation is “inexistent” because it is one of those things that gets fairly obvious from working with the engine.

Okay so in summation FName objects are great for fast comparisons (over FString).

So what if you explicitly name your subobjects created at runtime “TestSubObject” and you have 10 of these on various actors scattered around your game. Does the innate numbering system set these to “TestSubObject1”,“TestSubobject2”,“TestSubobject3”,…,“TestSubobject10” so that all these names are unique? I can see this being useful… I can also see it being a pain as well… or is there a way to set the default object name when you create a new class?

So what if you explicitly name your subobjects created at runtime “TestSubObject” and you have 10 of these on various actors scattered around your game. Does the innate numbering system set these to “TestSubObject1”,“TestSubobject2”,“TestSubobject3”,…,“TestSubobject10” so that all these names are unique? I can see this being useful… I can also see it being a pain as well… or is there a way to set the default object name when you create a new class?
[/QUOTE]

Not quite… I haven’t investigated the specifics, but subobjects also factor in their Outer for uniqueness. So, multiple actors can have a “MeshComponent0” and they will be unique. But multiple MeshComponents on a single actor will be numbered.

Ah that was “sort of” my original theory. So just to be sure I am grasping this correctly… An objects FName is a unique identifier for it within the Game/World. A subobject’s FName is unique in relation to it’s outer parent. Now I am making an assumption that the object’s FName is the same on the client as it is on the server, correct? So that when you replicate to the client that unique FName is used as a look up on the client machine. And the chain of subobject FNames allow data to replicate on subobjects without confusion between other subobjects with the same name on different objects?