Search Unity

is it okay to put initialisation logic into Data Components ?

Discussion in 'Data Oriented Technology Stack' started by Cassiopee, Dec 18, 2018.

  1. Cassiopee

    Cassiopee

    Joined:
    Oct 25, 2016
    Posts:
    15
    Like something like this

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. namespace Hybrid.Components
    4. {
    5.     public class PlayerInputForRTSComponent : MonoBehaviour
    6.     {
    7.         //Keybinding variables
    8.         //ZQSD
    9.         public KeyCode forward = KeyCode.Z;
    10.         public KeyCode backward = KeyCode.S;
    11.         public KeyCode left = KeyCode.Q;
    12.         public KeyCode right = KeyCode.D;
    13.     }
    14. }
    Let say i want to do this. Can i assign KeyCode directly into the component or should use a System to do that for me (if i must use a system, i dont know how to run a system once for initialisation) ?
    thanks
     
  2. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    521
    No this is ok
     
  3. Cassiopee

    Cassiopee

    Joined:
    Oct 25, 2016
    Posts:
    15
    oh, thanks.

    is it okay to put a Start() Method in it too ? (yes i start to be adventurous =O)
     
  4. Silve

    Silve

    Joined:
    May 7, 2013
    Posts:
    5
    In ComponentSystem you can override OnCreateManager() which as implied is run once when created.
    There is also OnStartRunning which is run once every time the system becomes enabled.

    If what you are looking for are some initial values editable through the editor then you can always use an IComponentData with a ComponentDataWrapper that you then read from in one of the above mentioned methods.
     
  5. Cassiopee

    Cassiopee

    Joined:
    Oct 25, 2016
    Posts:
    15
    OnCreateManager() manage entity when created and added to the system and OnStartRunning() run once when the system start working (and run another time if the system is stopping because no entity is there and a entity came back again). Did i understand you correctly ?

    If yes OnCreateManager() would do the job. But my class still require an OnUpdate() method. Should i create one and leave it empty ?
    Thanks