Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Disable rope inside animation event callback
#1
Hi, I am trying to disable rope at runtime inside both animation event callback and statemachinebehavior, but when "ObiRope.ropeBlueprint = null" is executed, DestroyImmediate will be called inside BurstColliderWorld.cs, which is not allowed by unity, it will throw an error as follows:

Destroying GameObjects immediately is not permitted during physics trigger/contact, animation event callbacks or OnValidate. You must use Destroy instead.
UnityEngine.Object: DestroyImmediate (UnityEngine.Object)
Obi.BurstColliderWorld: DecreaseReferenceCount () (at Assets/Obi/Scripts/Common/Backends/Burst/Collisions/BurstColliderWorld.cs:61)
Obi.BurstSolverImpl: Destroy () (at Assets/Obi/Scripts/Common/Backends/Burst/Solver/BurstSolverImpl.cs:186)
Obi.BurstBackend: DestroySolver (Obi.ISolverImpl) (at Assets/Obi/Scripts/Common/Backends/Burst/BurstBackend.cs:21)
Obi.ObiSolver:Teardown () (at Assets/Obi/Scripts/Common/Solver/ObiSolver.cs:873)
Obi.ObiSolver:RemoveActor (Obi.ObiActor) (at Assets/Obi/Scripts/Common/Solver/ObiSolver.cs:1165)
Obi.ObiActor:RemoveFromSolver () (at Assets/Obi/Scripts/Common/Actors/ObiActor.cs:362)
Obi.ObiActor:OnDisable () (at Assets/Obi/Scripts/Common/Actors/ObiActor.cs:328)


I tested to change DestroyImmediate to Destroy, currently everything works fine, but I'm fully aware of it is always recommended to use Destroy over DestroyImmediate, so I'm wondering you are intentionally use DestroyImmediate to prevent some unwanted behaviors, if so, should I keep using DestroyImmediate? And what are the workarounds for this problem? (except move my code to coroutine, it has to be synchronized at exact time in order to achieve my expected behavior)
Reply
#2
(10-04-2022, 01:21 PM)jacob Wrote: I tested to change DestroyImmediate to Destroy, currently everything works fine, but I'm fully aware of it is always recommended to use Destroy over DestroyImmediate, so I'm wondering you are intentionally use DestroyImmediate to prevent some unwanted behaviors, if so, should I keep using DestroyImmediate? And what are the workarounds for this problem? (except move my code to coroutine, it has to be synchronized at exact time in order to achieve my expected behavior)

You can't use Destroy() in editor. That's the reason why DestroyImmediate() is used instead, since the collision world might be destroyed in-editor when you switch simulation backends. Using Destroy() instead will cause all sorts of issues during edit mode, since multiple collision worlds will start to spawn in your scene.

If you intend to remove all actors from a solver during an animation, you might want to call Destroy or DestroyImmediate depending on whether you're in editor or play mode. You can use Application.isPlaying to check for this.
Reply
#3
(11-04-2022, 07:59 AM)josemendez Wrote: You can't use Destroy() in editor. That's the reason why DestroyImmediate() is used instead, since the collision world might be destroyed in-editor when you switch simulation backends. Using Destroy() instead will cause all sorts of issues during edit mode, since multiple collision worlds will start to spawn in your scene.

If you intend to remove all actors from a solver during an animation, you might want to call Destroy or DestroyImmediate depending on whether you're in editor or play mode. You can use Application.isPlaying to check for this.
Appreciated! Imma stick with burst anyway, but yeah, I'll add the check just in case.
Reply