Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Obi Rod Blueprint in Script
#1
Hello!

I want to add the Obi Rod Blueprint to the Obi Rod in a Script, is this even possible?
The reason is, that I manipulate the Control Points in the Blueprint, depending on which case I have.
And when I add the Blueprint first to the Rod, then the manipulation of the Control Points in the general Obi Rod Blueprint Script has no effect anymore…

Or is there a way to change the Control Points in Script afterwards?

Thank you in advance for your help!

Greetings
Mona
Reply
#2
(07-01-2021, 09:18 AM)MonaGermany Wrote: Hello!

I want to add the Obi Rod Blueprint to the Obi Rod in a Script, is this even possible?
The reason is, that I manipulate the Control Points in the Blueprint, depending on which case I have.
And when I add the Blueprint first to the Rod, then the manipulation of the Control Points in the general Obi Rod Blueprint Script has no effect anymore…

Or is there a way to change the Control Points in Script afterwards?

Thank you in advance for your help!

Greetings
Mona
Hi there,

You can create/modify blueprints at runtime, create/modify curve control points, and assign the blueprint to a rope at runtime. It's explained in detail (with sample code) here: http://obi.virtualmethodstudio.com/tutor...ctors.html

Don't expect to be able to modify existing ropes by changing their blueprint after it has been instantiated, though.

Just to make things clear: once you instantiate an actor, it is no longer tied to the blueprint in any way. Blueprints act as a "instruction manual" for the actor to know were to place particles and how to interconnect them using constraints. In this regard, they act just like prefabs: once you instantiate a prefab, modifying the prefab has no impact on the existing instances.

Control points only exist as a way to easily define a curve along which to place particles and define the rope's rest shape. Neither the curve nor its control points have any impact on existing ropes once their simulation has begun.
Reply
#3
(07-01-2021, 09:55 AM)josemendez Wrote: Hi there,

You can create/modify blueprints at runtime, create/modify curve control points, and assign the blueprint to a rope at runtime. It's explained in detail (with sample code) here: http://obi.virtualmethodstudio.com/tutor...ctors.html

Don't expect to be able to modify existing ropes by changing their blueprint after it has been instantiated, though.

Just to make things clear: once you instantiate an actor, it is no longer tied to the blueprint in any way. Blueprints act as a "instruction manual" for the actor to know were to place particles and how to interconnect them using constraints. In this regard, they act just like prefabs: once you instantiate a prefab, modifying the prefab has no impact on the existing instances.

Control points only exist as a way to easily define a curve along which to place particles and define the rope's rest shape. Neither the curve nor its control points have any impact on existing ropes once their simulation has begun.

Thank you for your quick Answer!
I had a look at the Sample Code and tried it out.
But I still have two problems: 
1. The Rod is in the Hirachy not under the Solver, so it is not assigned to the Solver and probably will not be simulated correctly.
2. The Blueprint is still not added to the Rod, so when I click play I don't see the Rod at all.

So that is the Code so far: 

IEnumerator Start()
    {
        // create an object containing both the solver and the updater:
        GameObject solverObject = new GameObject("solver", typeof(Obi.ObiSolver), typeof(Obi.ObiFixedUpdater));
        Obi.ObiSolver solver = solverObject.GetComponent<Obi.ObiSolver>();
        Obi.ObiFixedUpdater updater = solverObject.GetComponent<Obi.ObiFixedUpdater>();

        // add the solver to the updater:
        updater.solvers.Add(solver);

        // create the blueprint: (ltObiRopeBlueprint, ObiRodBlueprint)
        var blueprint = ScriptableObject.CreateInstance<Obi.ObiRodBlueprint>();

        // Procedurally generate the rod path (a simple straight line):
        blueprint.path.Clear();
        blueprint.path.AddControlPoint(Vector3.zero, -Vector3.right, Vector3.right, Vector3.up, 0.1f, 0.1f, 1, 1, Color.white, "start");
        blueprint.path.AddControlPoint(Vector3.one, -Vector3.right, Vector3.right, Vector3.up, 0.1f, 0.1f, 1, 1, Color.white, "end");
        blueprint.path.FlushEvents();

        // generate the particle representation of the rod (wait until it has finished):
        yield return blueprint.Generate();

        // create a rod:
        GameObject rodObject = new GameObject("rod", typeof(Obi.ObiRod), typeof(Obi.ObiRopeExtrudedRenderer));

        // get component references:
        Obi.ObiRod rod = rodObject.GetComponent<Obi.ObiRod>();
        Obi.ObiRopeExtrudedRenderer rodRenderer = rodObject.GetComponent<Obi.ObiRopeExtrudedRenderer>();

        // load the default rod section:
        rodRenderer.section = Resources.Load<Obi.ObiRopeSection>("DefaultRodSection");

        // instantiate and set the blueprint:
        rod.rodBlueprint = ScriptableObject.Instantiate(rodBlueprint);

        // parent the cloth under a solver to start simulation:
        rod.transform.parent = solver.transform;

       
    }

Greetings
Mona
Reply
#4
Hi Mona,

I can't reproduce either issue using your code. You're explicitly setting the blueprint and parenting the cloth under the solver, so there's no reason for this to not work unless there's any error preventing the script from completing execution.

Do you get any errors in the console when executing this?
Reply
#5
(08-01-2021, 10:50 AM)josemendez Wrote: Hi Mona,

I can't reproduce either issue using your code. You're explicitly setting the blueprint and parenting the cloth under the solver, so there's no reason for this to not work unless there's any error preventing the script from completing execution.

Do you get any errors in the console when executing this?

Hi !
No I don't get any errors. It works, that the Solver and the rod are added to the Scene. But the Blueprint is not added to the rod and the rod is not assigned to the solver...
Reply
#6
(08-01-2021, 11:00 AM)MonaGermany Wrote: Hi !
No I don't get any errors. It works, that the Solver and the rod are added to the Scene. But the Blueprint is not added to the rod and the rod is not assigned to the solver...

Both things work for me... can you step trough the code using the debugger, and see if it actually hits these two lines?:

Code:
// instantiate and set the blueprint:
rod.rodBlueprint = ScriptableObject.Instantiate(rodBlueprint);

// parent the cloth under a solver to start simulation:
rod.transform.parent = solver.transform;
Reply
#7
(08-01-2021, 11:30 AM)josemendez Wrote: Both things work for me... can you step trough the code using the debugger, and see if it actually hits these two lines?:

Code:
// instantiate and set the blueprint:
rod.rodBlueprint = ScriptableObject.Instantiate(rodBlueprint);

// parent the cloth under a solver to start simulation:
rod.transform.parent = solver.transform;
So I added Breakpoints to these two lines and debugged it. 
It stopped at the first line - at this point only the solver was added to scene. 
When I clicked continue the rod was added to the scene (without blueprint).
It did not stop at the second break Point at all ...
Reply
#8
I don't know if it's a typo or not, but in your code I had to replace "rodBlueprint" with "blueprint" in this line:
Quote:rod.rodBlueprint = ScriptableObject.Instantiate(blueprint);

it would not compile otherwise, since rodBlueprint isn't defined anywhere.

Maybe you have a member variable in your class named "rodBlueprint", but initialized to null? it would cause Unity to attempt to instantiate a null object, raising an exception ("the Object you want to instantiate is null") and stopping execution. That would generate a rope with no blueprint and would not parent it to the solver, which is exactly the behavior you're getting.

Weirdly specific I know, but it's the only explanation that comes to mind.
Reply
#9
(08-01-2021, 02:09 PM)josemendez Wrote: I don't know if it's a typo or not, but in your code I had to replace "rodBlueprint" with "blueprint" in this line:

it would not compile otherwise, since rodBlueprint isn't defined anywhere.

Maybe you have a member variable in your class named "rodBlueprint", but initialized to null? it would cause Unity to attempt to instantiate a null object, raising an exception ("the Object you want to instantiate is null") and stopping execution. That would generate a rope with no blueprint and would not parent it to the solver, which is exactly the behavior you're getting.

Weirdly specific I know, but it's the only explanation that comes to mind.
It works! Thank you so much Sonrisa 
Maybe you can help me with another little question:
Can i also change the damping in the solver in this code? 
Until now I did not find a possibilty to do this.
Reply
#10
Code:
solver.parameters.damping = 0.5f; // or any value you wish
solver.UpdateParameters();
Reply