Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Runtime rope deserialization issue
#5
Code:
ObiRopeBlueprint blueprint = ScriptableObject.CreateInstance<ObiRopeBlueprint>();
            int filter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 0);
            blueprint.pooledParticles = 0;
            blueprint.thickness = Config.Thickness;
            blueprint.resolution = 2;
            //particleCount = ropeLength / ropeThickness * resolution

            blueprint.path.Clear();
            blueprint.path.AddControlPoint(Config.Front.localPosition, -Vector3.right, Vector3.right, Vector3.up, 0.1f, 0.1f, 0.8f, filter, Color.white, "start");
            blueprint.path.AddControlPoint(Config.Back.localPosition, -Vector3.right, Vector3.right, Vector3.up, 0.1f, 0.1f, 0.8f, filter, Color.white, "end");
            blueprint.path.RecalculateLenght(Matrix4x4.identity, 0.00001f, 7);
           
            float totalParticleCount = 30;
            blueprint.resolution = totalParticleCount * Config.Thickness / blueprint.path.Length;
            blueprint.path.FlushEvents();

            ObiParticleAttachment frontAttachment = ObiRope.gameObject.AddComponent<ObiParticleAttachment>();
            frontAttachment.attachmentType = ObiParticleAttachment.AttachmentType.Static;
            frontAttachment.target = Config.Front;
            frontAttachment.particleGroup = blueprint.groups[0];

            ObiParticleAttachment backAttachment = ObiRope.gameObject.AddComponent<ObiParticleAttachment>();
            backAttachment.attachmentType = ObiParticleAttachment.AttachmentType.Static;
            backAttachment.target = Config.Back;
            backAttachment.particleGroup = blueprint.groups[1];

            ObiRope.OnBlueprintLoaded += ObiRopeLoaded;
            ObiRope.ropeBlueprint = blueprint;

            ObiFixedUpdater.solvers.Add(ObiSolver);

Code:
private void ObiRopeLoaded(ObiActor actor, ObiActorBlueprint blueprint)
        {
            // load particle positions
            for (int i = 0; i < ObiSolver.positions.count; i++)
            {
                if (i < ParticlePositions.Count)
                {
                    ObiSolver.positions.SetVector3(i, ParticlePositions[i]);
                }
                ObiSolver.velocities.SetVector3(i, Vector3.zero);
            }
           
            ParticlePositions.Clear();
        }

As I said, if I wait 2 seconds and run the code in ObiRopeLoaded part, all works perfectly fine
Reply


Messages In This Thread
Runtime rope deserialization issue - by aderae - 18-09-2023, 01:48 PM
RE: Runtime rope deserialization issue - by aderae - 18-09-2023, 02:44 PM