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


Messages In This Thread
Disable rope inside animation event callback - by jacob - 10-04-2022, 01:21 PM