Search Unity

System that have to run once

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

  1. Cassiopee

    Cassiopee

    Joined:
    Oct 25, 2016
    Posts:
    15
    Hello,

    long story short, how can i add/remove entities from a system ?

    in my multiplayer prototype i have 2 gameObject holding 2 camera.
    When Player 2 enter the game, i need a system that disable Player 1's on Player's 2 Client. (and vise versa)

    but how can i get a system to do it only once ? i dont want it to disable things every frame in the OnUpdate method.

    Also, for the moment i use that to filter what entity my Moving system should act on

    Code (CSharp):
    1.     protected override void OnUpdate()
    2.     {
    3.         foreach (var entity in GetEntities<Group>())
    4.         {
    5.             if (entity.networkIdentity.isLocalPlayer)
    6.             {
    7.                 Move(entity)
    8.             }
    9.         }
    10.     }
    But that mean my script look through every entity each frame to look at isLocalPlayer. wouldn't it be better to remove !isLocalPlayer from the system ?
     
  2. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    521
    Systems only run if there are entities who matches the ComponentGroup of a system...
    So you can work with tags on entities or with event entities
     
  3. Cassiopee

    Cassiopee

    Joined:
    Oct 25, 2016
    Posts:
    15
    i'm not sure to understand. how can i put tags checks in my private struct group ?
    also i never heard of event entities either...

    currently my private struct look like this

    Code (CSharp):
    1.     private struct Group
    2.     {
    3.         public Transform transform;
    4.  
    5.         public NetworkIdentity networkIdentity;
    6.  
    7.         public PlayerInput playerInput;
    8.         public PlayerCameraVariablesComponent variables;
    9.  
    10.     }
    i cant disable player input nor variables and i dont think disabling transform or networkidentity will do any good.