![]() |
Help Issue Saving/Loading Particle Positions in play mode using ObiRope v7.0 - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html) +--- Thread: Help Issue Saving/Loading Particle Positions in play mode using ObiRope v7.0 (/thread-4485.html) Pages:
1
2
|
Issue Saving/Loading Particle Positions in play mode using ObiRope v7.0 - ozeecode - 28-04-2025 Hello, I managed to save and reload particle positions in ObiRope v6.x using code under the Copy ropes in play mode thread. However, this no longer works in ObiRope v7.x. Could you help me identify what I might be missing? Here’s my current code: Code: public void Load(Vector3[] particlePositions, Vector3 lastParticlePosition) The save sections look like this: Code: int positionCount = rope.elements.Count; Thanks! RE: Issue Saving/Loading Particle Positions in play mode using ObiRope v7.0 - ozeecode - 29-04-2025 I tried something like this: I instantiated a rope and saved it in a "long" form via a blueprint (to ensure a higher particle count). This way, I no longer needed to add new particles to rope.elements. Specifically, I commented out the following code block: Code: // while (rope.elements.Count < particleCount) By doing this, I could adjust the rope’s particle count by only removing particles, without adding new ones. However, I’m still unsure how to handle cases where I do need to add new elements. Thanks! RE: Issue Saving/Loading Particle Positions in play mode using ObiRope v7.0 - josemendez - 29-04-2025 Hi! (29-04-2025, 07:27 AM)ozeecode Wrote: rope.ActivateParticle(); // This doesn't have an actorIndex anymore. It always uses activeParticleCount now. It's by far the most common case and the most efficient one as well: activate the last inactive particle, which is done by just bumping a counter. (29-04-2025, 07:27 AM)ozeecode Wrote: Specifically, I commented out the following code block: This code appends a new element that links the first particle of the previous element with the new active particle. It should link the second particle of the previous element instead. (29-04-2025, 07:27 AM)ozeecode Wrote: However, this no longer works in ObiRope v7.x. Could you help me identify what I might be missing? Corrected the above two issues (ActivateParticle and reversed elements), tested it and it seems to work ok. Could you specify what you mean by "not working"? does it result in an error? does it do nothing? does it do something else that what you expected? kind regards, RE: Issue Saving/Loading Particle Positions in play mode using ObiRope v7.0 - ozeecode - 29-04-2025 (29-04-2025, 07:53 AM)josemendez Wrote: Hi! Hello, thank you for your response . First of all, I want to ask this: When I directly instantiate the ObiRope prefab and place it into the solver, since it doesn't have any particles yet, this line throws the following error: Code: rope.ActivateParticle(); Code: IndexOutOfRangeException: Reading from index 0 is out of range of '0' Capacity. To overcome this, I first spawn the rope and then load the saved data: Code: Rope rope = Spawner.Instance.CreateRope(startAttachmentPoint.PinPoint); Is there a way to remove this delay? Code: await UniTask.Delay(100); As for my main issue, if I use the Load() method I sent in my first message exactly as it is, none of the particle positions are set. They all remain in their initial positions. In other words, my rope appears as it was set in the blueprint. I suspect this happens because it's an asynchronous process, but I’m not sure. Thank you. RE: Issue Saving/Loading Particle Positions in play mode using ObiRope v7.0 - josemendez - 29-04-2025 (29-04-2025, 08:55 AM)ozeecode Wrote: Hello, thank you for your response . Actors aren't loaded into the solver right away, as this could happen while the simulation is underway on a different thread and cause race conditions. They're usually loaded at the start of the next simulation step. Just wait until the actor has been loaded. Actors have an OnBlueprintLoaded event for this purpose (similarly, they have an OnBlueprintUnloaded event). There's also a isLoaded boolean that you can check later on, or on a coroutine. (29-04-2025, 08:55 AM)ozeecode Wrote: As for my main issue, if I use the Load() method I sent in my first message exactly as it is, none of the particle positions are set. They all remain in their initial positions. In other words, my rope appears as it was set in the blueprint. I suspect this happens because it's an asynchronous process, but I’m not sure. Correct: actor loading in Obi is asynchronous and always has been, so if your script worked in previous versions is likely out of luck. kind regards RE: Issue Saving/Loading Particle Positions in play mode using ObiRope v7.0 - ozeecode - 29-04-2025 Hello again, I’ve managed to work around the async issues for now. Regarding your comment when adding particles: Quote:This code appends a new element that links the first particle of the previous element with the new active particle. It should link the second particle of the previous element instead. Code: while (rope.activeParticleCount < particleCount) I’ve also figured out what this causes. When used this way, all the ObiStructuralElement entries I add to the array are incorrect. ![]() As a result, the saved and loaded rope does not appear the same. ![]() ![]() I think the difference between the two images is caused by this issue. Thank you. RE: Issue Saving/Loading Particle Positions in play mode using ObiRope v7.0 - josemendez - 29-04-2025 (29-04-2025, 10:52 AM)ozeecode Wrote: Hello again, What this code does is simply append a new element and a new particle to the rope. "()" being a particle and "-----" being an element linking 2 particles, a rope looks like this: ( A )------( B )-----( C )------( D ) And the list of elements for this rope would be: element 1: particle1 = A, particle2 = B element 2: particle1 = B, particle2 = C, element 3: particle1 = C, particle2 = D (29-04-2025, 10:52 AM)ozeecode Wrote: I was not able to acquire index of the particle that was activated last. Just like elements, particles are stored in a list. Activating a particle simply adds an active particle to the list. So rope.activeParticleCount is the index of the particle that's going to get activated next, and rope.activeParticleCount-1 the index of the last active particle. So when adding a new element, its first particle must be the second particle of the previous element. Its second particle must of course be the new particle we are about to activate. Code: rope.elements.Add(new ObiStructuralElement kind regards RE: Issue Saving/Loading Particle Positions in play mode using ObiRope v7.0 - ozeecode - 29-04-2025 Thank you for your response. I’ve managed to correctly access the particle indices. Currently, the particle positions appear correct, but only the particles I manually added are not visible in the scene. I also checked with the extrude renderer, and the rope seems a bit incomplete. ![]() ![]() Do I need to do anything extra to make the particles visible in the scene? RE: Issue Saving/Loading Particle Positions in play mode using ObiRope v7.0 - ozeecode - 29-04-2025 Alright, I just realized I forgot to add this: Code: rope.CopyParticle(rope.activeParticleCount - 1, rope.activeParticleCount); Here’s the final version of the Load method: Code: public void Load() However, in the last line of the Load method, within the AddConstraints method, something seems to be going wrong. I adapted the code from the Adding/Removing Constraints section to my use case, but it seems like colliderB isn’t linking to the last particle, while colliderA is working as intended. Here’s the AddConstraints() method: Code: [SerializeField] private ObiCollider colliderA; This script used to work normally in v6. As far as I can tell, the only change is the tearRope parameter: batch.AddConstraint(firstParticle, colliderA, new Vector3(0, 0, 0), Quaternion.identity, 0, 0, float.PositiveInfinity); What could be my mistake here? https://www.youtube.com/watch?v=A-5ZFtkJ89k Yellow sphere that is visible on the video is colliderA and the Blue one is colliderB Thanks. RE: Issue Saving/Loading Particle Positions in play mode using ObiRope v7.0 - ozeecode - 30-04-2025 I still haven’t figured out what I’m doing wrong in the Load() method. |