-
Hi, I'm curious if the following behavior is by design, if I am misusing it, or if this is a bug. I have a use case where the array of components arrived as an object[], which contains references to struct components (boxing isn't problematic for my case here). I want to create an entity from those components. Here's a simple example:
Interestingly, the Entity contains the component with the correct type when viewed in a debugger, including with correct state. However, the Entity does not report that it has the component. I'm curious if something is happening with typing and casting internally, however, the debugger does show the correct type. I am able to work around this by retrieving the types (e.g. (ComponentType)(x.GetType()) ) and creating a ComponentType[] array, using that to create an archetype, and then setting each component (using only the object reference). This is not a big deal to me as I'll be putting this logic in a service object anyway, but I'm curious if this is intended. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
@Mathetis Hey there and thanks! :) Well... You are using that correctly and it should work. May i ask which version you are using? It might be a bug, however the latest beta/preview version (1.2.3.4-beta) had some improvements and the issue might be gone :) |
Beta Was this translation helpful? Give feedback.
-
Just looked at this, this is actually intended behavior rn.
|
Beta Was this translation helpful? Give feedback.
Just looked at this, this is actually intended behavior rn.
The generic overloads are favored in such a case since there's no
world.Create(object[])
overload... there's however :world.Create(Span<ComponentType>
orworld.Create(ComponentType[]);
which can be used to create the entity. After this you can set the components from anobject[]
array like this :entity.SetRange(object[]);
:)