Basic Scene Setup

This page explains how to create a new scene with a character in it to use as a starting point for many of the sample tutorials.

The required steps are quite simple:

  1. Create a new scene by right clicking in the Project window and selecting Create/Scene.
  2. Drag the desired character model into the Hierarchy window and position it at the origin (0,0,0). Practically any character will work if you have animations for them, or you can use the standard character included with Animancer which is located at Assets/Plugins/Animancer/Samples/Art/Default Humanoid/DefaultHumanoid.fbx.
  3. Disable the Apply Root Motion toggle on the character's Animator component. Most samples won't involve any Root Motion and those that do will tell you to re-enable it.
  4. Select the character and click the Add Component button at the bottom of the Inspector then start typing AnimancerComponent and click on that component when it appears in the list.
  5. Select the Main Camera and reposition it to better view the character. For the DefaultHumanoid model, (2,1,-1) is a good position with (0,-60,0) as the rotation.

Ground Plane

If you want a ground plane:

  1. Right click in the Hierarchy window and create a 3D Object/Plane.
  2. Reset its Transform position to (0,0,0).
  3. Go to its MeshRenderer component and change the material to Stone-Light.

There are also a few optional scripts located in Assets/Plugins/Animancer/Samples/Code which can be useful.

Click here if you're wondering why the Transform Inspector looks different from Unity's default in that image.

It's because of a plugin called Inspector Gadgets (also made by Kybernetik like Animancer).

It replaces the default Transform Inspector to add features like the [C][P][S] buttons on the right to Copy and Paste values between objects, and Snap them to the grid or the [=] button on the left which toggles the Scale field from a single value to the regular x/y/z vector field.

Inspector Gadgets Pro adds many more features, but the enhanced Transform Inspector is included in the Lite version for free.

Orbit Controls

Most of the samples can be viewed fine from a fixed camera angle, but if you add the OrbitControls script to the Main Camera it will allow you to rotate the camera around a Focal Point point by holding Right Click and dragging the mouse. You can also scroll to zoom in and out.

Time Scale

The TimeScale script can be added to anything in the scene to give you a slider in the Inspector which controls how fast the game runs. This can be very useful for observing transitions and other events in slow motion.

Buttons

Some of the samples use the SampleButton script to dynamically create a list of buttons at runtime.

It holds references to the other components which need to be controlled:

public class SampleButton : MonoBehaviour
{
    [SerializeField] private RectTransform _Transform;
    [SerializeField] private Button _Button;
    [SerializeField] private Text _Text;
    [SerializeField] private float _Spacing = 10;

It uses an OnValidate method to automatically gather those references so you they don't need to be manually assigned in the Inspector:

    protected virtual void OnValidate()
    {
        gameObject.GetComponentInParentOrChildren(ref _Transform);
        gameObject.GetComponentInParentOrChildren(ref _Button);
        gameObject.GetComponentInParentOrChildren(ref _Text);
    }

The main purpose of this script is to be placed in the scene's Canvas at an appropriate location and have other scripts call AddButton to initialize copies of it as necessary:

  • When the given index is 0, the button initializes itself.
  • Otherwise, it clones itself and initializes the clone.
    public SampleButton AddButton(
        int index,
        string text,
        UnityAction onClick)
    {
        SampleButton button = this;

        if (index != 0)
        {
            button = Instantiate(button, button._Transform.parent);

            Vector2 position = button._Transform.anchoredPosition;
            position.y -= index * (button._Transform.sizeDelta.y + button._Spacing);
            button._Transform.anchoredPosition = position;
        }

        button._Button.onClick.AddListener(onClick);
        button._Text.text = text;
        button.name = text;

        return button;
    }
}