Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug / Crash  Destroying GameObjects immediately is not permitted during physics trigger/contact
#1
Code:
public void AttachRope()
        {
            _blueprint = ScriptableObject.CreateInstance<ObiRopeBlueprint>();
            var fatherConnectionPoint = _playersContainer[PlayerCharacter.Father].ConnectionPoint;
            var sonConnectionPoint = _playersContainer[PlayerCharacter.Son].ConnectionPoint;
            Vector3 father = ObiRope.transform.InverseTransformPoint(fatherConnectionPoint.position);
            Vector3 son = ObiRope.transform.InverseTransformPoint(sonConnectionPoint.position);
            lineFromObiRope.SetStartEndPositions(father, son);
            int allLayers = (1 << 16) - 1;
            int excludeLayer15 = ~(1 << 15);
            int finalMask = allLayers & excludeLayer15;

            int filter = ObiUtils.MakeFilter(finalMask,
                1);
            _blueprint.path.Clear();
            _blueprint.groups.Clear();
            _blueprint.path.AddControlPoint(father,
                -father.normalized,
                father.normalized,
                Vector3.zero,
                _controlPointsMass,
                _controlPointsMass,
                1,
                filter,
                Color.white,
                "start");

            _blueprint.path.AddControlPoint(son,
                -son.normalized,
                son.normalized,
                Vector3.zero,
                _controlPointsMass,
                _controlPointsMass,
                1,
                filter,
                Color.white,
                "end");

            _blueprint.path.FlushEvents();
            _blueprint.Generate();
            ObiRope.ropeBlueprint = _blueprint;

            var pinConstraints = ObiRope.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
            pinConstraints.Clear();
            var batch = new ObiPinConstraintsBatch();

            batch.AddConstraint(ObiRope.solverIndices[0],
                _fatherConnectionPointObiCollider,
                Vector3.zero,
                Quaternion.identity,
                0,
                0,
                float.PositiveInfinity);

            batch.AddConstraint(ObiRope.solverIndices[_blueprint.activeParticleCount - 1],
                _sonConnectionPointObiCollider,
                Vector3.zero,
                Quaternion.identity,
                0,
                0,
                float.PositiveInfinity);

            batch.activeConstraintCount = 2;
            pinConstraints.AddBatch(batch);
            ObiRope.SetConstraintsDirty(Oni.ConstraintType.Pin);
        }
I made a rope hitch like in the Hook example. And now every time I get this error in ObiCollisionWorld when I use the above AttachRope method.
Code:
public void DecreaseReferenceCount()
        {
            if (--refCount <= 0 && gameObject != null)
                DestroyImmediate(gameObject); 
        }
Code:
Destroying GameObjects immediately is not permitted during physics trigger/contact, animation event callbacks, rendering 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:189)
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:905)
Obi.ObiSolver:RemoveActor (Obi.ObiActor) (at Assets/Obi/Scripts/Common/Solver/ObiSolver.cs:1201)
Obi.ObiActor:RemoveFromSolver () (at Assets/Obi/Scripts/Common/Actors/ObiActor.cs:362)
Obi.ObiRope:set_ropeBlueprint (Obi.ObiRopeBlueprint) (at Assets/Obi/Scripts/RopeAndRod/Actors/ObiRope.cs:152)
_src.Scripts.PlayerFeatures.Connection.ThreadProxy_s.ThreadProxy:AttachRope () (at Assets/_src/Scripts/PlayerFeatures/Connection/ThreadProxy's/ThreadProxy.cs:124)
_src.Scripts.PlayerFeatures.Connection.ConnectionHandler:AttachPhysicalRope () (at Assets/_src/Scripts/PlayerFeatures/Connection/ConnectionHandler.cs:407)
_src.Scripts.PlayerFeatures.Connection.ConnectionHandler:EnablePermanentPhysicalConnection () (at Assets/_src/Scripts/PlayerFeatures/Connection/ConnectionHandler.cs:398)
_src.Scripts.PlayerFeatures.Connection.ConnectionHandler/<ChangeMode>d__46:MoveNext () (at Assets/_src/Scripts/PlayerFeatures/Connection/ConnectionHandler.cs:276)
Cysharp.Threading.Tasks.CompilerServices.AsyncUniTaskMethodBuilder:Start<_src.Scripts.PlayerFeatures.Connection.ConnectionHandler/<ChangeMode>d__46> (_src.Scripts.PlayerFeatures.Connection.ConnectionHandler/<ChangeMode>d__46&) (at Library/PackageCache/com.cysharp.unitask@c170af5642/Runtime/CompilerServices/AsyncUniTaskMethodBuilder.cs:111)
_src.Scripts.PlayerFeatures.Connection.ConnectionHandler:ChangeMode (_src.Scripts.PlayerFeatures.Connection.ConnectionMode,single)
_src.Scripts.Core.PermanentConnectionZone:EnablePermanentMode () (at Assets/_src/Scripts/Core/PermanentConnectionZone.cs:78)
UnityEngine.Events.UnityEvent:Invoke ()
_src.Scripts.Core.TwoPlayersTrigger:CheckPlayersInTrigger () (at Assets/_src/Scripts/Core/TwoPlayersTrigger.cs:69)
_src.Scripts.Core.PermanentConnectionZone:OnTriggerStay (UnityEngine.Collider) (at Assets/_src/Scripts/Core/PermanentConnectionZone.cs:47)

Code:
_src.Scripts.PlayerFeatures.Connection.ThreadProxy_s.ThreadProxy:AttachRope () (at Assets/_src/Scripts/PlayerFeatures/Connection/ThreadProxy's/ThreadProxy.cs:124)
124 point is 
Code:
ObiRope.ropeBlueprint = _blueprint;

in AttachRope method

Iam use [6.5.2] obiRope
Reply


Messages In This Thread
Destroying GameObjects immediately is not permitted during physics trigger/contact - by Alexander34 - 17-09-2024, 01:14 PM