Putting a Deformable in "DontDestroyOnLoad" and then loading a new scene causes the Deformers to no longer be able to make changes
wedgiebee opened this issue Β· comments
Think I found a bug! π
- Create a Deformable object and give it a Deformer
- Call DontDestroyOnLoad(), passing in the Deformable gameObject
- Load a scene using UnityEngine.SceneManagement.SceneManager.LoadScene() - be sure to use LoadSceneMode.Single, because this doesn't seem to be an issue when you use LoadSceneMode.Additive
- When the scene is loaded, observe that the Deformable remains deformed, BUT making changes to the Deformer no longer updates the deformation :(
Good find! I think the issue stems from how Deformables update. They register/unregister themselves with a DeformableManager in OnEnable/OnDisable. Every frame, the DeformableManager loops through all of its registered Deformables and updates them. By default, at runtime, deformables assign themselves to a default manager. When you load a new scene, the default manager is unloaded (destroyed). This is normally fine since the deformables get destroyed along with it, however; now the deformable that didn't get destroyed on load doesnt have a manager, hence it not updating.
There's a few potential solutions:
- The default Deformable Manager should not be destroyed on load either (this is probably the correct solution)
- A new default manager can be created and assigned like this:
someDeformable.Manager = DeformableManager.GetDefaultManager(true);
- Update the special deformable manually
someDeformable.UpdateMode = UpdateMode.Custom;
...
private void Update()
{
someDeformable.PreSchedule();
someDeformable.Schedule().Complete();
someDeformable.ApplyData();
}
I haven't been able to test any of these solutions yet, but I'll look into it when I get home π
Calling DontDestroyOnLoad
on the default deformable manager seems to fix it in my tests. You can grab the changes on the develop branch if you want to test it for yourself π
Awesome, that did it! Thanks!