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. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Assign RigEffector in Script

Discussion in 'Animation Rigging' started by nocanwin, Jun 23, 2020.

  1. nocanwin

    nocanwin

    Joined:
    May 7, 2009
    Posts:
    176
    I'm setting up a lot of characters to use AR and I'm making an editor script to generate some general purpose rigs. How do I go about setting up a RigEffector for targets I generate? I started to dig into it a little, but didn't see it anything obvious.
     
  2. simonbz

    simonbz

    Unity Technologies

    Joined:
    Sep 28, 2015
    Posts:
    295
    Hi,

    You can use the following functions to manage RigEffectors in a RigBuilder hierarchy:
    Code (CSharp):
    1. RigBuilder.AddEffector(Transform transform, RigEffectorData.Style);
    2. RigBuilder.RemoveEffector(Transform transform);
    3. bool RigBulder.ContainsEffector(Transform transform);
     
  3. miron83

    miron83

    Joined:
    Oct 28, 2015
    Posts:
    6
    Hi,

    I made a script for editor which is using the animation rigging package, to automate the process of connecting and creating constrains and controls for my models.
    Everything works perfectly, the rig constrains and controls with effectors builds great and everything works in play mode. This is until I try to build the app or even build the asset bundles with AssetBundle package.

    When I try I get this message:

    Assets\Scripts\RigBinder.cs(366,15): error CS1061: 'RigBuilder' does not contain a definition for 'AddEffector' and no accessible extension method 'AddEffector' accepting a first argument of type 'RigBuilder' could be found (are you missing a using directive or an assembly reference?)

    the line 366:
    Code (CSharp):
    1. RigBuilder.AddEffector(_obj.transform,MakeEffectorStyle(_tempColor));
    code for making style

    Code (CSharp):
    1. private RigEffectorData.Style MakeEffectorStyle(Color _color){
    2.         //new Color(1f, 0f, 0f, 0.5f)
    3.         RigEffectorData.Style _style = new RigEffectorData.Style()
    4.         {
    5.             // shape = EditorHelper.LoadShape("BoxEffector.asset"),
    6.             shape = DefaultEffectorShape,
    7.             color = _color,
    8.             size = 0.10f,
    9.             position = Vector3.zero,
    10.             rotation = Vector3.zero
    11.         };
    12.         return _style;
    13.     }
    DefaultEffectorShape in editor script as i need to load an asset from library:

    Code (CSharp):
    1. myTarget.DefaultEffectorShape = (Mesh)AssetDatabase.LoadAssetAtPath("Packages/com.unity.animation.rigging/Editor/Shapes/BoxEffector.asset", typeof(Mesh));
    the build ends with an error and i don't know where the problem lies.
    If i comment out that line the build process works fine but then after downloading the asset the script is missing an action.

    Do you have any suggestions how to go around that or what might be wrong?
     
    Last edited: May 4, 2022
  4. simonbz

    simonbz

    Unity Technologies

    Joined:
    Sep 28, 2015
    Posts:
    295
    RigEffectors are not a runtime concept. The functions in `RigBuilder` and `Rig` components are editor only and are not present in the assembly at runtime. Try surrounding your function calls with `#if UNITY_EDITOR ... #endif` to make sure your code does not evaluate outside of the editor.