Obi Official Forum
Help How do you create a rope at runtime? - 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 How do you create a rope at runtime? (/thread-3385.html)



How do you create a rope at runtime? - NailEngine - 30-03-2022

I am trying to create a rope at runtime with a static attachment and a dynamic attachment. Much like the chain example. There is an example script called "RuntimeRopeGenerator" that looked promising, but has been completely commented out -- it looks like it's probably deprecated. Where can I find an example of how to create a rope purely from code?

Just to be clear -- I am trying to create a rope without having to create a blueprint asset in-editor; I am attempting to do everything from code.


RE: How do you create a rope at runtime? - josemendez - 31-03-2022

(30-03-2022, 10:51 PM)NailEngine Wrote: I am trying to create a rope at runtime with a static attachment and a dynamic attachment. Much like the chain example. There is an example script called "RuntimeRopeGenerator" that looked promising, but has been completely commented out -- it looks like it's probably deprecated. Where can I find an example of how to create a rope purely from code?

Just to be clear -- I am trying to create a rope without having to create a blueprint asset in-editor; I am attempting to do everything from code.

Hi there!

The manual explains how, along with sample code:
http://obi.virtualmethodstudio.com/manual/6.3/scriptingactors.html

You also have an example included with the asset, the "RopeGrapplingHook" sample scene uses an entirely procedural rope. Check out the /Obi/Samples/RopeAndRod/SampleResources/Scripts/GrapplingHook.cs script, and ..../ExtendableGrapplingHook.cs for a version that extends itself over time instead of appearing instantly.

The steps to create a rope from code are conceptually the same you follow to create a rope in-editor:

Blueprint:
- Create a rope blueprint.
- Add control points to the blueprint to define the rope's shape.
- Call the blueprint's Generate() coroutine.

Rope:
- Create a ObiRope component and any renderer you wish (extruded/chain/line/mesh)
- Assign the blueprint to the rope.
- Put the rope into a solver (if you haven't got any solver around, you will need to create one).


RE: How do you create a rope at runtime? - NailEngine - 31-03-2022

Hey, thanks for getting back to me so quickly! This has helped a lot, and I have a working demo. Do I have to call blueprint.Generate() within a coroutine? My code is not currently setup for this being an enumerator, so I'm just trying to see if I'll run into any trouble here.


RE: How do you create a rope at runtime? - josemendez - 31-03-2022

(31-03-2022, 06:13 PM)NailEngine Wrote: Hey, thanks for getting back to me so quickly! This has helped a lot, and I have a working demo. Do I have to call blueprint.Generate() within a coroutine? My code is not currently setup for this being an enumerator, so I'm just trying to see if I'll run into any trouble here.

There’s a hint globe in the manual with a direct answer to this Guiño:

“Remember that you don't have to rely on StartCoroutine to run a coroutine, or run it asynchronously. You can manually advance it using IEnumerator.MoveNext.“

If you don’t need any control over the generation process and don’t mind a slight pause if it takes long, you can also call GenerateImmediate() instead, which is a synchronous call.


RE: How do you create a rope at runtime? - NailEngine - 31-03-2022

(31-03-2022, 06:44 PM)josemendez Wrote: There’s a hint globe in the manual with a direct answer to this Guiño:

“Remember that you don't have to rely on StartCoroutine to run a coroutine, or run it asynchronously. You can manually advance it using IEnumerator.MoveNext.“

Oh, for sure, I'm doing that. But I guess that relies on those coroutines not yielding WaitForXXX right? Because there are expectations on rendered frames, time, etc. I just want to make sure.


RE: How do you create a rope at runtime? - josemendez - 31-03-2022

(31-03-2022, 06:51 PM)NailEngine Wrote: Oh, for sure, I'm doing that. But I guess that relies on those coroutines not yielding WaitForXXX right? Because there are expectations on rendered frames, time, etc. I just want to make sure.

The Generate() coroutine returns a struct containing a string message and a progress percentage. No WaitForSeconds, WaitForEndOfFrame or similar stuff. The main reason this is a coroutine is that you may want to show a progress bar of some sort if your rope is really long and takes more than a few milliseconds to generate.