Search Unity

ComponentDataWrapper wont show in inspector?

Discussion in 'Entity Component System' started by avvie, May 12, 2018.

  1. avvie

    avvie

    Joined:
    Jan 26, 2014
    Posts:
    74
    Hey people,

    I just started exploring ECS, and i am trying to get a handle on it. So i am attempting to make a single cube rotate. I follow, kinda, the simple example of rotation given by unity. The following uses exactly the same structure as the IComponentData structs defined in the entities package.

    1. using System;
    2. using Unity.Entities;
    3. [Serializable]
    4. public struct RotationSpeed : IComponentData {
    5. public float Value;
    6. }
    7. // This wrapper component is currently necessary to add ComponentData to GameObjects.
    8. // In the future we want to make this wrapper component automatic.
    9. public class RotationSpeedComponent : ComponentDataWrapper<RotationSpeed> { }
    Problem is that unlike the ones in the entity package when i try to drag and drop them in the inspector it just informs me that it doesnt derive from monobehavior. I am trying to see why that happens, because it makes no sense to me.
    ComponentDataWrapper derives from ComponentDataWrapperBase (or something close to this), which in turn derives from Monobehaviour.

    As most probably know the code above is from the simple example, like literally copy paste.. In the inspector i have a cube that has:
    Game Object Entity
    Rotation Component
    a couple of others as well from the entities package. I looked at their code and is almost identical.
     
  2. Soaryn

    Soaryn

    Joined:
    Apr 17, 2015
    Posts:
    328
    The only thing I can think of, is if you are making your own cs files, the files MUST be named the same as the wrapper class, and not the struct for the inspector to understand it atm
     
    JakobHAndersen and avvie like this.
  3. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    Yes what Soaryn said. You have to name the file after the wrapper class, not the IComponentData struct.
     
  4. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    I'll just add to what the other two said: It's because ComponentDataWrapper<T> and SharedComponentDataWrapper<T> are MonoBehaviour-derived, and MonoBehaviours in your project require the class name to match the file name for the editor to understand where they are.

    (I wish there was an attribute or something to do this manually for cases like this).
     
    avvie likes this.
  5. avvie

    avvie

    Joined:
    Jan 26, 2014
    Posts:
    74
    Thank you people you are amazing! I cant believe that it never crossed my mind to check the name. That worked instantly.
    Now to see if I can make this simple system to work

    Edit: given its the simple example for pure ecs that unity provides, why does the system update the rotation just on the first frame?
     
    Last edited: May 12, 2018