Search Unity

Question How can I access an entity in subscene from MonoBehaviour?

Discussion in 'Entity Component System' started by Luemus, Oct 14, 2022.

  1. Luemus

    Luemus

    Joined:
    May 20, 2013
    Posts:
    107
    Hello everyone, I was trying to make Cinemachine work (or just make a custom script that follows the entity) however I am having hard times figuring out how can I access the entity from the MonoBehaviour. I was following this tutorial from Turbo Makes Games however it is outdated and not working anymore.

    Basically I am trying to copy the position and rotation of an entity to a GameObject. How can I achieve this?
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,779
    Just use same Unity version as on the tutorials. Always.

    You should be asking this question in the scripting sub forum. Ti's isn't support forum.[/]
     
    Last edited: Oct 14, 2022
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Hi, couple of options:
    1. Add required MonoBehaviour to the Entity via EntityManager.AddComponentObject and use managed system (SystemBase) to iterate upon those (.WithoutBurst().Run()). Set position & rotation as needed.
    2. Use sync job to write to the Transform via TransformAccessArray (e.g. see job and how to add Transform);
    3. Use bakers / conversion, convert Transform to Entities Transforms and use components from the Transforms package to sync basically in the same way (via TAA, handled by Transforms systems);
     
    Last edited: Oct 14, 2022
    Luemus and Antypodish like this.
  4. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    It's not "General" though. :p
     
    Antypodish likes this.
  5. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,779
    Oh lol, in DOTS... I thought it was in general. Sorry then.
     
    Luemus and xVergilx like this.
  6. Luemus

    Luemus

    Joined:
    May 20, 2013
    Posts:
    107
    Thanks, I'll try!