Custom Ability Manual Start Problem

atmuc

Member
I created an ability that plays an animation. When I start ability by code, I see ability is enabled. It will not update AbilityChange and Ability Index at the animator. If I set Ability Index and AbilityChange on the animator from the editor window, it works.

When I set Start Type to Automatic, It works fine. It updates the animator and plays my animation.

It is an agent character.

How can I solve that problem?

var started = UltimateCharacterLocomotion.TryStartAbility(ability);

1641293521447.png
 

atmuc

Member
Thanks, I will use Generic when I will play just animation in my ability. I will do more than playing just animation in my ability.

My problem is Manual start does not update the animator. Is it a bug or do I have to do something more?
 

ChristianWiele

Moderator
Staff member
If you start the ability through code, is the ability set to active in the editor window? The animator parameters are set independent from the start mode, so it does not depend on manual/automatic. But it might be that the ability is not started at all (either it has a low priority, or it is actively blocked by another ability).
 

atmuc

Member
It worked after I added that code to my ability. Is it normal?

protected override void AbilityStarted()
{
base.AbilityStarted();

m_CharacterLocomotion.UpdateAbilityAnimatorParameters(true);
}
 

ChristianWiele

Moderator
Staff member
Usually, you should not be required to call UpdateAbilityAnimatorParameters explicitly, unless you change some parameters in code dynamically. There are only few abilities that do this (you can search the code). But you have always call the base methods when overriding.
I have asked Justin to look into this.
 

Justin

Administrator
Staff member
Once the ability is started the start type isn't used. My guess is something else is going on. Maybe your animator has a transition that is consuming the value and it only transitions correctly if the ability is started at a certain time? You can see the parameter changes by enabling logging on the Animator Monitor. This could also explain why forcing the parameter update again works.
 

atmuc

Member
Once the ability is started the start type isn't used. My guess is something else is going on. Maybe your animator has a transition that is consuming the value and it only transitions correctly if the ability is started at a certain time? You can see the parameter changes by enabling logging on the Animator Monitor. This could also explain why forcing the parameter update again works.
I checked it with Animator Monitor Log. It does not update Animator parameters unless I call m_CharacterLocomotion.UpdateAbilityAnimatorParameters(true);

OnButtonClick calls that code;

var abilities = UltimateCharacterLocomotion.GetAbilities<Magic>();

Debug.LogFormat("PlayerCharacterController:Magic:abilities length:{0}", abilities.Length);

if (abilities.Length > 0)
{
var ability = abilities[0];
var started = UltimateCharacterLocomotion.TryStartAbility(ability);
Debug.LogFormat("PlayerCharacterController:Magic:started:{0}", started);
}

Log is

PlayerCharacterController:Magic:abilities length:1
PlayerCharacterController:Magic:started:True

When I call
m_CharacterLocomotion.UpdateAbilityAnimatorParameters(true);
I can see
277 Changed AbilityIndex to 1002 on GameObject Character_Male_Baird_01_,Agent3 (1).
 

Justin

Administrator
Staff member
I created a new ability:

Code:
public class MyAbility : Ability {}

And started it manually. When I started it the index was successfully changed. Maybe this call stack will help your debugging?

Code:
6 Changed AbilityIndex to 501 on GameObject Nolan.
UnityEngine.Debug:Log(Object)
Opsive.UltimateCharacterController.Character.AnimatorMonitor:SetAbilityIndexParameter(Int32) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/AnimatorMonitor.cs:690)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion:UpdateAbilityAnimatorParameters(Boolean) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:1358)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion:UpdateDirtyAbilityAnimatorParameters() (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:1024)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion:UpdateAnimator() (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:846)
Opsive.UltimateCharacterController.Character.CharacterLocomotion:Move(Single, Single, Single) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/CharacterLocomotion.cs:490)
Opsive.UltimateCharacterController.Game.KinematicCharacter:Move(Boolean) (at Assets/Opsive/UltimateCharacterController/Scripts/Game/KinematicObjectManager.cs:237)
Opsive.UltimateCharacterController.Game.KinematicObjectManager:FixedUpdate() (at Assets/Opsive/UltimateCharacterController/Scripts/Game/KinematicObjectManager.cs:880)
 

atmuc

Member
@Justin I think your Nolan is a player character. Can you try it with an agent character that a camera controller does not init it?
 

atmuc

Member
I found the problem.

KinematicObjectManager forces UltimateCharacterLocomotion to update animator parameters.
Attaching look source registers UltimateCharacterLocomotion to KinematicObjectManager.
If there is no look source, there will be no registration and animator parameter update.

When it is a player character camera controller starts that registration parameter. If it is an agent there must be local look source.

Have I solved UCC architecture well? :)
 
Top