Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Two components of the same type on one entity

Discussion in 'Entity Component System' started by gamayun, Mar 12, 2020.

  1. gamayun

    gamayun

    Joined:
    Nov 20, 2012
    Posts:
    34
    Hi everybody,

    It's been a while I wanted to add two ConfigurableJoint to my entities and I really don't know how to do it.

    1) If I try in my Archetype I have this answer:

    Code (CSharp):
    1.         eArch = eMngr.CreateArchetype(
    2.             typeof(LocalToWorld),
    3.             typeof(Translation),
    4.             typeof(Rotation),
    5.             typeof(RenderMesh),
    6.             typeof(BoxCollider),
    7.             typeof(Rigidbody),
    8.             typeof(ConfigurableJoint),
    9.             typeof(ConfigurableJoint));
    10.  
    ArgumentException: It is not allowed to have two components of the same type on the same entity. (ConfigurableJoint and ConfigurableJoint)

    2) If I try the IBufferElementData I have this answer:

    ...
    Code (CSharp):
    1. public struct MyBufferElement : IBufferElementData
    2. {
    3.     // These implicit conversions are optional, but can help reduce typing.
    4.     public static implicit operator ConfigurableJoint(MyBufferElement e)
    5.     {
    6.        return e.Value;
    7.     }
    8.     public static implicit operator MyBufferElement(ConfigurableJoint e)
    9.     {
    10.        return new MyBufferElement { Value = e };
    11.     }
    12.  
    13.     // Actual value each buffer element will store.
    14.     public ConfigurableJoint Value;
    15. }
    16.  
    ...
    Code (CSharp):
    1.  
    2.         eArch = eMngr.CreateArchetype(
    3.             typeof(LocalToWorld),
    4.             typeof(Translation),
    5.             typeof(Rotation),
    6.             typeof(RenderMesh),
    7.             typeof(BoxCollider),
    8.             typeof(Rigidbody),
    9.             typeof(MyBufferElement));
    10.  
    ArgumentException: MyBufferElement contains a field of UnityEngine.ConfigurableJoint, which is neither primitive nor blittable.

    Ok so IBufferElementData are for types like int etc. but not ConfigurableJoint

    I tried to think of a better Entity but really my entities need those 2 ConfigurableJoints

    So please anyone, do you know how I can do that?

    Cheers,

    Thierry
     
  2. mr-gmg

    mr-gmg

    Joined:
    Aug 31, 2015
    Posts:
    62
    What do you have inside of ConfigurableJoint? Why can't you make ConfigurableJoint as IBufferElementData?
    Code (CSharp):
    1. public struct ConfigurableJoint : IBufferElementData {
    2. //...
    3. }
     
  3. mr-gmg

    mr-gmg

    Joined:
    Aug 31, 2015
    Posts:
    62
    oh, now I realized it is a UnityEngine.ConfigurableJoint which is a class, so, nohow I think, but I'm the beginner in ECS, so, maybe I simply don't know something.
    Have you tried ECS Unity Physics package?
     
  4. mr-gmg

    mr-gmg

    Joined:
    Aug 31, 2015
    Posts:
    62
    I never did like that and I'm just curious, what is the point of doing like that?
    Code (CSharp):
    1. eArch = eMngr.CreateArchetype(
    2.             typeof(LocalToWorld),
    3.             typeof(Translation),
    4.             typeof(Rotation),
    5.             typeof(RenderMesh),
    6.             typeof(BoxCollider),
    7.             typeof(Rigidbody),
    8.             typeof(MyBufferElement));
    Is it really working? Looks like entity manager ignores all wrong types. But as I said, I don't know the truth and it is interesting for me to know.
    Screenshot_34.png
     
    Last edited: Mar 12, 2020
  5. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,574
    gamayun likes this.
  6. gamayun

    gamayun

    Joined:
    Nov 20, 2012
    Posts:
    34
    Hi @Antypodish thanks for your answers, I'll investigate what you pointed to me, you must be right, UnityEngine.ConfigurableJoint and not using the ECS Unity Physics package may be the problem. I'll look into this and get back to you
     
  7. gamayun

    gamayun

    Joined:
    Nov 20, 2012
    Posts:
    34
    Hi again @Antypodish and everyone with the same question I had: Actually looking into the physics samples, it makes sense to have 2 kind of entities: firstly, my entities WITHOUT my 2 joints in the Archetype and WITH 2 indexes on entities that I'm going to describe right away: THEN I add another type of entities, different from the previous ones, and each of them will only have in their Archetype one joint joining entities of the previous type... hmmm sorry for my english, I hope it makes sense! Anyway I'm going to try this out and I'll post my progression here.
    Cheers
    Thierry