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

Affecting scale of 'child' entity based off of data in a parent entity (pinnochio's nose)

Discussion in 'Entity Component System' started by HeliosJack, Aug 20, 2021.

  1. HeliosJack

    HeliosJack

    Joined:
    Aug 15, 2013
    Posts:
    41
    Here's the Pinnochio's Nose Problem (tm) I'm facing:

    Imagine we have a whole bunch of Pinnochio entities which are made up of a few primitive shapes, one of which is a nose. When one of the pinnochio entities lies, we increase the num_lies int in the PinnochioData struct. What I want is to then have the nose then grow (change z scale) in response to that change.

    Right now the nose is just a primitive shape childed in the editor which is converted to an entity along with the parent.

    What are my options here If I want this to be burstable and parallel? Creating a reference to the parent would require the entitymanager, which would prevent its use in parallel, right?

    How would this sort of thing be accomplished?
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,984
    You don't need the EntityManager for this. Traditionally, the tool you are looking for is called ComponentDataFromEntity<T> which lets you look up components on other entities from a job. However, in an Entities.ForEach, you can use the shorthand GetComponent<T>().

    Reading (getters only) the parent should work in parallel.
     
    xVergilx likes this.
  3. HeliosJack

    HeliosJack

    Joined:
    Aug 15, 2013
    Posts:
    41
    Eyyooooo, it works!!