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

System not working

Discussion in 'Entity Component System' started by zehreken, Sep 6, 2018.

  1. zehreken

    zehreken

    Joined:
    Jun 29, 2009
    Posts:
    112
    I have just copied the Rotator.cs from one of the Unity example videos, attached it to a cube but it is not working. Entity Debugger shows RotatorSystem as 'not run'. If I delete the foreach block it runs. Unity 2018.2.6f1
    Code (CSharp):
    1. using Unity.Entities;
    2. using UnityEngine;
    3.  
    4. class Rotator : MonoBehaviour
    5. {
    6.     // The data - editable in the inspector
    7.     public float Speed;
    8. }
    9.  
    10. class RotatorSystem : ComponentSystem
    11. {
    12.     struct Components
    13.     {
    14.         // Define what components are required for this
    15.         // ComponentSystem to handle them.
    16.         public Transform transform;
    17.         public Rotator rotator;
    18.     }
    19.  
    20.     override protected void OnUpdate()
    21.     {
    22.         // We can immediately see a first optimization.
    23.         // We know delta time is the same between all rotators,
    24.         // so we can simply keep it in a local variable
    25.         // to get better performance.
    26.         float deltaTime = Time.deltaTime;
    27.  
    28.         // ComponentSystem.GetEntities<Group>
    29.         // lets us efficiently iterate over all GameObjects
    30.         // that have both a Transform & Rotator component
    31.         // (as defined above in Group struct).
    32.         foreach (var e in GetEntities<Components>())
    33.         {
    34.             e.transform.rotation *= Quaternion.AngleAxis(e.rotator.Speed * deltaTime, Vector3.up);
    35.         }
    36.     }
    37. }
     
    erenaydin likes this.
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,580
    Have you copied bootstrap too?
     
  3. zehreken

    zehreken

    Joined:
    Jun 29, 2009
    Posts:
    112
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,580
  5. zehreken

    zehreken

    Joined:
    Jun 29, 2009
    Posts:
    112
    You are right, I shouldn't stay stuck with this simple example but I was just curious. Thank you.
     
  6. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    You need to add a GameObjectEntity component otherwise the components on the game object will not be injected into the entity world to be seen there.
     
    Tony_Max likes this.
  7. zehreken

    zehreken

    Joined:
    Jun 29, 2009
    Posts:
    112
    It works, thanks a lot. I knew it was a 'minor' detail. :)
     
  8. erenaydin

    erenaydin

    Joined:
    Mar 1, 2011
    Posts:
    381
    I also noticed if one of the components is missing on the gameobject, the entity will stop.
     
  9. Vicotin

    Vicotin

    Joined:
    Mar 18, 2014
    Posts:
    7
    Did you solve the "not run" problem?