Mix icon indicating copy to clipboard operation
Mix copied to clipboard

The component type Id's are not consistent throughout different executions

Open unravel-dev opened this issue 10 years ago • 1 comments

execution 1: auto e = world.CreateEntity(); e.AddComponent<PositionComponent>(100, 100); - ID = 0 e.AddComponent<VelocityComponent>(10, 10); - ID = 1

execution 2: auto e = world.CreateEntity(); e.AddComponent<VelocityComponent>(10, 10); - ID = 0 // different from the last time e.AddComponent<PositionComponent>(100, 100); - ID = 1 // different from the last time

This may cause problems if something like serialization of the entities and pools takes place. Though it can be worked around.

You can map the type_index to the runtime generated ones, but the type_index hash function returns a size_t type which is not consistent on 32 bit and 64 bit architectures. My suggestion is some kind of consistent uint32_t hash on the component's type name but that would require some dependency on a rtti/reflection library. Your call :). Though a really nice library :)

unravel-dev avatar Jan 27 '16 13:01 unravel-dev

Yeah, I haven't thought about serialization issues really. One work-around is to make sure the IDs are the same every time yourself, using Component<T>::GetID() and always in the same order you want. Will look into this at some point, thanks for registering issues and the feedback!

arvidsson avatar Jan 28 '16 16:01 arvidsson