Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Suggestion / Idea  Problem with the Obi Solver Structure
#14
Hi Bill,

I slightly modified the actor's Awake method, to support multiple actors in the prefab's hierarchy without any downsides. It is also slightly cleaner and concise. Here's the updated version:

Code:
protected void Awake()
        {
#if UNITY_EDITOR

            // Check if this script's GameObject is in a PrefabStage
            var prefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetPrefabStage(gameObject);

            if (prefabStage != null)
            {
                // Only create a solver if there's not one up our hierarchy.
                if (GetComponentInParent<ObiSolver>() == null)
                {
                    // Add our own environment root and move it to the PrefabStage scene
                    var newParent = new GameObject("ObiSolver (Environment)", typeof(ObiSolver), typeof(ObiLateFixedUpdater));
                    newParent.GetComponent<ObiLateFixedUpdater>().solvers.Add(newParent.GetComponent<ObiSolver>());
                    UnityEngine.SceneManagement.SceneManager.MoveGameObjectToScene(newParent, gameObject.scene);
                    transform.root.parent = newParent.transform;
                }
            }
#endif
        }
Reply


Messages In This Thread
RE: Problem with the Obi Solver Structure - by josemendez - 26-11-2019, 10:00 AM