Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Debug.Log() in ECS foreach?

Discussion in 'Entity Component System' started by Quit, Mar 21, 2023.

  1. Quit

    Quit

    Joined:
    Mar 5, 2013
    Posts:
    63
    Hello,

    Is there anything like Debug.Log() for entities inside the foreach loop?

    I have a foreach with a query and trying to figure out which entities are being included in the SystemAPI.Query(). However, Debug.Log() only prints out the entities which had the components added during the bake time.

    If I add PeriodicFixedTimerData component during the runtime, the debug print doesn't print this entity out,. Nonetheless the component data itself gets updated.

    I'm doing something wrong, I guess.

    upload_2023-3-21_2-10-52.png

    If I add Debug.Log("entity: " + entity) above the if() statement, it only ever prints out entities which had this component added during the bake step.

    Thanks for your help.
     

    Attached Files:

  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,217
    That means that it is only the baked entities that the query is finding. Nothing special about Debug.Log here. It is providing a clue to whatever problem you are facing.
     
    Antypodish likes this.
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,754
    As mentioned above, you job process only what queries matches.
    So if your entity doesn't have required components, or is marked as prefab, it will not be processed in the job. Hence debug.log will not be called.
     
  4. apkdev

    apkdev

    Joined:
    Dec 12, 2015
    Posts:
    277
    Maybe this is the problem part? It's normal that the foreach only works for entities with the specified component. It should also automatically include any entities you create at runtime.
     
    Last edited: Mar 22, 2023
  5. Quit

    Quit

    Joined:
    Mar 5, 2013
    Posts:
    63
    My silly mistake. return from foreach() is actually return from the function itself (what I needed was continue)... Should stop writing code after midnight :facepalm: