Posts: 18
Threads: 1
Joined: Oct 2021
Reputation:
0
(19-10-2021, 12:02 PM)josemendez Wrote: Yes, those are the pooled (inactive) particles. Quoting myself:
A certain amount of extra particles are preallocated when you create a rope blueprint. These are collectively referred to as the particle "pool", and start out inactive (invisible, and not used in the simulation). If you do not plan on resizing or cutting the rope at runtime, you can set the blueprint's pool size to zero. No inactive particles will be added to the rope.
The reason for preallocating particles and activating/deactivating them instead of just creating/destroying particles at runtime is -as with most pooling strategies in Unity- to avoid runtime allocation and minimize garbage collection. See:
http://obi.virtualmethodstudio.com/manua...setup.html
Assuming you do have a non-empty pool, if you want to only get the active particles you should do:
Code: for (int i = 0; i < actor.activeParticleCount; ++i)
{
Debug.Log(solver.positions[actor.solverIndices[i]]);
}
In fact, is my object Obi Rope the same actor? The index of the actor is the same Obi Rope as the index in the hierarchy ??
PhoneRope1 this is essentially actors[0]
PhoneRope2 this is essentially actors[1]???? Thanks
ropes.PNG (Size: 4.14 KB / Downloads: 21)
Posts: 6,321
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
19-10-2021, 01:30 PM
(This post was last modified: 19-10-2021, 01:32 PM by josemendez.)
(19-10-2021, 01:26 PM)Matbee Wrote: In fact, is my object Obi Rope the same actor? The index of the actor is the same Obi Rope as the index in the hierarchy ??
PhoneRope1 this is essentially actors[0]
PhoneRope2 this is essentially actors[1]???? Thanks
No, actors aren't added to the solver in the same order they appear in the hierarchy. They are added in the order their Start() methods are called, so the exact order is undefined (because the order in which Unity calls Start for different objects is also undefined).
Why do you want to access the solver's internal actor array? you already have a reference to each rope, right? ropes are actors, so you can just do:
PhoneRope1.solverIndices, PhoneRope1.activeParticleCount, etc.
ObiActor is just the base class for anything that's made of particles, and that includes ropes.
Posts: 18
Threads: 1
Joined: Oct 2021
Reputation:
0
(19-10-2021, 01:30 PM)josemendez Wrote: No, actors aren't added to the solver in the same order they appear in the hierarchy. They are added in the order their Start() methods are called, so the exact order is undefined (because the order in which Unity calls Start for different objects is also undefined).
Why do you want to access the solver's internal actor array? you already have a reference to each rope, right? ropes are actors, so you can just do:
PhoneRope1.solverIndices, PhoneRope1.activeParticleCount, etc.
ObiActor is just the base class for anything that's made of particles, and that includes ropes. Is it possible to somehow get a list of all the ropes in the solver?
Posts: 6,321
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
19-10-2021, 02:50 PM
(This post was last modified: 19-10-2021, 03:00 PM by josemendez.)
(19-10-2021, 02:36 PM)Matbee Wrote: Is it possible to somehow get a list of all the ropes in the solver?
If there’s only ropes in the solver, that would be the actors array you referred to in the previous question. If there’s other kinds of actors (rods, for instance), just check the type of each one and discard anything that is not a rope.
This assumes that you understand inheritance/polimorphism in C#, if that’s not the case I’d recommend reading about the subject and getting your C# up to speed.
Posts: 18
Threads: 1
Joined: Oct 2021
Reputation:
0
(19-10-2021, 02:50 PM)josemendez Wrote: If there’s only ropes in the solver, that would be the actors array you referred to in the previous question. If there’s other kinds of actors (rods, for instance), just check the type of each one and discard anything that is not a rope. Yes, there are only ropes in my solver, but I want to get them in the correct order
Posts: 6,321
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
19-10-2021, 03:02 PM
(This post was last modified: 19-10-2021, 03:04 PM by josemendez.)
(19-10-2021, 02:52 PM)Matbee Wrote: Yes, there are only ropes in my solver, but I want to get them in the correct order
Why not using Unity’s methods then? GetChild(n) will give you the nth children of a transform, in the same order they appear in the hierarchy.
https://docs.unity3d.com/ScriptReference...Child.html
Posts: 18
Threads: 1
Joined: Oct 2021
Reputation:
0
(19-10-2021, 03:02 PM)josemendez Wrote: Why not using Unity’s methods then? GetChild(n) will give you the nth children of a transform, in the same order they appear in the hierarchy.
https://docs.unity3d.com/ScriptReference...Child.html I will get ObiRope objects, I will have access to the solver, but in the actors, the order of the ropes may still be wrong
Posts: 6,321
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
(19-10-2021, 04:23 PM)Matbee Wrote: I will get ObiRope objects, I will have access to the solver, but in the actors, the order of the ropes may still be wrong
Why are you concerned about the order in which the ropes are internally added to the solver? Can’t really think of a reason why it would matter at all.
If you want them in the order in which they appear in the scene hierarchy, Unity already gives you that.
Posts: 18
Threads: 1
Joined: Oct 2021
Reputation:
0
20-10-2021, 09:23 AM
(This post was last modified: 20-10-2021, 09:27 AM by Matbee.)
(19-10-2021, 04:36 PM)josemendez Wrote: Why are you concerned about the order in which the ropes are internally added to the solver? Can’t really think of a reason why it would matter at all.
If you want them in the order in which they appear in the scene hierarchy, Unity already gives you that. can i somehow limit the length of the rope?
(19-10-2021, 04:36 PM)josemendez Wrote: Why are you concerned about the order in which the ropes are internally added to the solver? Can’t really think of a reason why it would matter at all.
If you want them in the order in which they appear in the scene hierarchy, Unity already gives you that. since other objects are associated with this actor, and it is necessary that the order is observed in order to animate the desired objects after working with a certain rope
Posts: 6,321
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
20-10-2021, 09:53 AM
(This post was last modified: 20-10-2021, 10:03 AM by josemendez.)
(20-10-2021, 09:23 AM)Matbee Wrote: can i somehow limit the length of the rope?
Don't really understand this question... ropes already have a limited length, their rest length. They won't exceed this length (that is, unless you attach their ends to transforms using static attachments, in that case you would be forcing them to stretch).
(20-10-2021, 09:23 AM)Matbee Wrote: since other objects are associated with this actor, and it is necessary that the order is observed in order to animate the desired objects after working with a certain rope
Still don't understand.... why not using the order in which they appear in the hierarchy? the "solver.actors" array in the solver contains *exactly* the same data as Unity's transform hierarchy, but in a random order as it's basically a set: order does not matter. Unity will give them to you ordered, which is what you need right? why access them trough the actors array?
As I mentioned before, transform.GetChild() will give them to you in the order they appear in the scene hierarchy. So if you only have ropes inside the solver, you can access them ordered like this:
Code: var rope1 = solver.transform.GetChild(0).GetComponent<ObiRope>(); // first rope
var rope2 = solver.transform.GetChild(1).GetComponent<ObiRope>(); // second rope
var rope3 = solver.transform.GetChild(2).GetComponent<ObiRope>(); // third rope
If you have other objects mixed in, simply check whether or not they have a rope component.
|