Closed RuggeroVisintin closed 1 day ago
The reason why entities' names need to be unique in the first place is to allow the identification of an entity through a human-readable unique string.
Initially, names needed to be globally unique, but that didn't make sense anymore once scene deserialization was introduced, as names are serialized in the scene since they can be used to create relationships between entities, the same name might be used across different scenes, causing the check on the global scope to fail.
To overcome this issue, the concept of uniqueness scope was introduced with #331, which led to this bug. This commit tried to address the issue but proved unsuccessful.
Using the data provided in the example and the code, after loading the scene uniqueCounterMap
looks as follow
{
"global": {
"GameObject1": 0,
"GameObject2": 0,
"TriggerEntity": 0
},
"2a5e1096-c1b9-42c2-a0dc-eca13b2ca020": {
"GameObject1": 0,
"GameObject2": 0,
"TriggerEntity": 0
}
}
We can easily observe the entities have been registered in the global scope too, but with the wrong key. When no scene loading is involved, the JSON structure usually looks like this
{
"global": {
"GameObject": 1,
"GameObject1": 0
},
"2a5e1096-c1b9-42c2-a0dc-eca13b2ca020": {
"GameObject": 0,
"GameObject1": 0,
"TriggerEntity": 0
}
}
In general, we would expect the JSON structure to look more like this instead
{
"global": {
"GameObject": 2,
"GameObject1": 1
},
"2a5e1096-c1b9-42c2-a0dc-eca13b2ca020": {
"GameObject": 2,
"GameObject1": 1,
"TriggerEntity": 1
}
}
incrementallyUnique${typeOf(this)}
which uses the Entity type (the extended type) in an incremental way. When loading the scene the pattern isn't recognised and the keys in the global scope end up being GameObject1
and GameObject2
, leading to names not being incremented correctly.Provided names need to be unique only within a given scope, should the default name being provided by the scene, being an entity's parent scope, or should they be self assigned by an entity from the global scope?
Is there any added value other than pure cosmetic to add globally unique names at the entity's level?
Finalizing #377 to solve issue and opening new task to evaluate "Unique Names are assigned when an entity is registered in a scene" proposal
Description When deserializing an Existing Scene, newly created entities reuse the same unique name as some objects created in the scene
Code Snippet
Additional context Screenshot from the current version
Serialized scene being used test.spark.json