In this section we will learn how to link layers.

The linking process is used to smoothly blend in our desired Animator Profile in runtime.

Let's take at the linking functionality in the source code:

public void UnlinkAnimatorProfile() { ... }
public void LinkAnimatorProfile(GameObject itemEntity) { ... }
public void LinkAnimatorProfile(FPSAnimatorProfile newProfile) { ... }

The system has a way to link a Game Object, if it contains the Animator Profile. This is only possible, if your Game Object has an FPSEntityComponent:

Then, in your controller code you can just pass the weapon Game Object to the LinkAnimatorProfile method, and it will work as expected.

The UnlinkAnimatorProfile is used to blend out the currently active profile, which might be useful when you do not want to use the system at all.

Code example

Let's see how we can apply the linking in practice. Here's a code snippet from the demo:

private void EquipWeapon()
    var gun = _instantiatedWeapons[_activeWeaponIndex];
    _fpsAnimator.LinkAnimatorProfile(gun.gameObject); // Linking a new profile.
    _animator.CrossFade("CurveEquip", 0.15f);

In the demo project, when we are changing weapons, we effectively link a new animator profile from the active weapon.

You can link different animator profiles depending on the game play. For example, in the demo it is possible to achieve the unarmed state by pressing the T key:

if (Input.GetKeyDown(KeyCode.T))
    _isUnarmed = !_isUnarmed;

    if (_isUnarmed)

        _animator.SetFloat(OverlayType, 0);
        _userInput.SetValue(FPSAConstants.PlayablesWeightProperty, 0f);
        _userInput.SetValue("StabilizationWeight", 0f);

        _animator.SetFloat(OverlayType, (int) GetGun().overlayType);
        _userInput.SetValue("PlayablesWeight", 1f);
        _userInput.SetValue("StabilizationWeight", 1f);

As you can see, here we link an unarmedProfile whne toggling our feature. Additionally, we use the SetValue method of the UserInputController to adjust the Playables influence over the character upper body, so our Animator has a full control over the character pose.

Last updated