C# Kangaroo dynamic goal adjust

Is there C# implementation example of goal live editing, when the goals are created inside the C# component? Example: Changing the force based on a function dynamically, while the simulation is ongoing without resetting the Simulation.

    int counter = 0;
    double threshold = 1e-10;
    do
    {
      PS.Step(GoalList, false, threshold); 
      //Modify some goal strengths dynamically from the GoalList here.
      counter++;
    }while(PS.GetvSum() > threshold && counter < 100);

@DanielPiker

Hi @Kane_Borg

Sure - here’s a script that runs the solver and adjusts the goal properties each iteration
(in this case, just changing spring rest lengths as a sine function of iteration count, but hopefully gives the idea)
dynamicGoalAdjust.gh (9.5 KB)

1 Like

Great implementation example, thanks Daniel!

Hi @DanielPiker,

To dynamically edit the Strength in case Hinge goal or Stiffness in case of a Spring goal, can one just modify the field as you did with the dynamicGoalAdjust example or do you need to also modify the weightings in the goal object? At what point are the weightings set for the goal object?

My aim is to be able to deactivate and reactivate goals at will by setting their strengths to 0.

Yes, for OnCurve and Hinge, modifying the strength is enough, because those goals assign the strength to the Weighting themselves inside the Calculate method.

Not all goals are guaranteed to do this though. For example Pressure only assigns the weightings once, in the constructor, so if you wanted to modify them during solving, you’d need to set the Weighting directly.

1 Like

Thanks for clarifying!