Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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:
    2,384
    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:
    212
    @tertle, have you solved this problem?

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