Search Unity

GetComponentInParent (and therefore) StaticOptimizeEntity not working as expected

Discussion in 'Data Oriented Technology Stack' started by tertle, Jun 17, 2019.

  1. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    1,661
    Trying to use StaticOptimizeEntity on an entity prefab and it would just not add the static component.
    After debugging and stepping through, for some reason

    upload_2019-6-17_12-56-25.png

    The line
    Code (CSharp):
    1. go.GetComponentInParent<StaticOptimizeEntity>()
    is returning null even though the gameobject clearly has the StaticOptimizeEntity script and therefore the line

    Code (CSharp):
    1. flags |= StaticMask;
    is never entered.

    GetComponentInParent should return components on the same game object from documentation
    But for whatever reason it's not working here, startup order or something?

    This is an entity added via IDeclareReferencedPrefabs

    Code (CSharp):
    1. public void DeclareReferencedPrefabs(List<GameObject> referencedPrefabs)
    2. {
    3.     referencedPrefabs.Add(this.prefab);
    4. }
    Am I overlooking something stupid?

    -edit-

    should add, this seems to work fine for entities in scene being converted just not these prefabs.

    and this was tested in 2019.1.7f1
     
    Last edited: Jun 17, 2019
  2. rsodre

    rsodre

    Joined:
    May 9, 2012
    Posts:
    176
    @tertle, have you solved this problem?

    I also noticed that StaticOptimizeEntity seems to have no effect in a prefab.