Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Change Multi-Aim Constraint at runtime

Discussion in 'Scripting' started by Maroni100, Aug 17, 2022.

  1. Maroni100

    Maroni100

    Joined:
    Apr 29, 2016
    Posts:
    2
    Hello, I have a rig layer with a multi-aim constraint, it works normally, however, if I try to change its offset values at runtime, the values simply do not change

    it's my code
    Code (CSharp):
    1. myConstraint.data.offset = weaponPosition.spine.position
    editorprint.png

    what am i doing wrong? I've already tried to update the values using rigBuilder.build() but all riglayers stop working
     
  2. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,596
    Never used it before, but does unchecking Maintain Rotation Offset solve it? The documentation says, "Specifies whether to maintain the initial rotation offset between the Constrained Object and the Source Objects." so I would think it would stop your offset from changing.
     
  3. Maroni100

    Maroni100

    Joined:
    Apr 29, 2016
    Posts:
    2
    thanks for the reply, just unchecking main rotation offset doesn't work either
     
  4. Sylafrs

    Sylafrs

    Joined:
    Jun 25, 2013
    Posts:
    56
    Hello, sorry for waking this thread from the graveyard.
    I actually have the same issue, I didn't have it yesterday.

    What changed is that I tried modifying the offset from a StateMachineBehaviour (OnStateEnter/OnStateUpdate).
    Maybe a protection is in place to avoid IK changes while animating?
    I'll try to add a "isOffsetDirty" so that I update it in Update() instead and I'll let you know
     
  5. Sylafrs

    Sylafrs

    Joined:
    Jun 25, 2013
    Posts:
    56
    Re :)
    It did the trick, I hope it helps :)