Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  How to change the rest length of an existing rope at runtime?
#2
(26-05-2021, 09:27 PM)Hatchling Wrote: I've encountered a situation where I need to change the rest length of a rope that is already present in the scene.

I think I've figured out the solution, and the code seems to work, but I wanted to have you look over it to make sure I'm doing everything correctly (or if there's a better way).

I've added the following method inside ObiRopeBlueprintBase:

[code...]

Since I'm doing this after the rope has been made, I get the feeling I might not need to do this from the blueprint. But as far as I know this is where the "data" for the rope is stored, whereas the rope itself represents an instance. (RopeBlueprint is to Rope as Mesh is to MeshFilter/MeshRenderer)

As far as i can see, this code changes the rest length using a multiplier. Also, it changes the rest length of all constraints, so that they pull particles closer together or further apart. This doesn't really count as changing the rest length of the rope, since it changes both its length and its resolution (amount of particles per length unit). It's more like compressing/stretching the rope, similar to what the "stretching scale" parameter of the rope does.

As long as this is your intended result, the code is fine.


(26-05-2021, 09:27 PM)Hatchling Wrote: Do I, for example, need to call ObiActorBlueprint.OnBlueprintGenerate after making this modification?

OnBlueprintGenerate basically reloads the blueprint: removes the actor from the solver and immediately re-adds it, copying all particle and constraint data from the blueprint to the solver. If you're doing this at runtime, then it is a good idea to call OnBlueprintGenerate so that the changes to blueprint constraint rest lengths are applied.

A less taxing equivalent would be to modify the constraints loaded in the solver too, not just the ones in the blueprint. This would avoid having to reload particle data, since it does not change at all when you call your method.


(26-05-2021, 09:27 PM)Hatchling Wrote: It seems to me that since all ropes that share the same blueprint would have the same rest length.

Nope Sonrisa. The restLength value in the blueprint is used as the rope's initial rest length, but it can later change. Eg: you can change the rest length of a rope at runtime, using ObiRopeCursor (http://obi.virtualmethodstudio.com/tutor...ursor.html). So different instances of the same blueprint can end up having completely different rest lengths.

Same thing happens with tearable cloth: tearable cloth blueprints have a topology asset (a half-edge data structure), that is copied over to the instances. Then each individual instance can be independently torn in different ways. Tearing a cloth will only update its local copy of the topology.
Reply


Messages In This Thread
RE: How to change the rest length of an existing rope at runtime? - by josemendez - 27-05-2021, 09:05 AM