21-11-2019, 07:13 PM
(This post was last modified: 21-11-2019, 07:14 PM by josemendez.)
Hey,
Adding a solver to the prefab stage was much easier than I expected. Add this code anywhere in ObiActor.cs, now everytime you edit an actor prefab the prefab stage contains a solver at its root. Will clean this up a bit and include it in 5.0.1 for next week.
Adding a solver to the prefab stage was much easier than I expected. Add this code anywhere in ObiActor.cs, now everytime you edit an actor prefab the prefab stage contains a solver at its root. Will clean this up a bit and include it in 5.0.1 for next week.
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)
{
// Check if parent is null to ensure we are handling the root
if (gameObject.transform.parent != null)
return;
// 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.parent = newParent.transform;
}
#endif
}