AnimationGraph and C# Script

first of all, congrats to you and your team for the excellent work about Flax Engine: its graphics is awsome and all the Engine looks very intersting and promising.
I’m experimenting with Flax a little bit, particullary about AnimationGraph, State Machine and C# scripts.
Therefore, after importing my Character (from Mixamo), I set up a State Machine with Idle Animation connecting with Walk and Run States. I created two boolean properties (isWalking and isRunning), with which I’d like to drive my Player beheviour at runtime, throughout a script named Anims_Transiction.
My idea is simple as that: from default (Idle) state, if I push W-key, it will be fires walk animation, while pushing down Tab-key, the animation switches to Run State.
So far so good, but when I run the game, Flax does not peform this actions, seems like it’s not detects the Anims_Transiction script, despite the Anim_Graph proprieties were displayed into the Editor.
I tried to install Flax/Visual Studio plugin, but nothing is changed.
What’s wrong? Why seems the script doesn’t executed at run time?
Thanks in advance for your kindly support.

Could you post the script here?

That’s a bit hard for me to test, since it’s a picture instead of copy-able text. But anyways, it looks alright, except that you’re never resetting the parameter (param1 and param2) values to false.

Also, could you check the Output Log to make sure that your script actually compiled as intended?

Sorry, I reproduce here the script in text format, updating it based upon your suggestion:

using System;
using System.Collections.Generic;
using FlaxEngine;

namespace Game
    public class Anims_Transition : Script
        public bool isWalking { get; set; } = false;
        public bool isRunning { get; set; } = false;

        private AnimGraphParameter param1;
        private AnimGraphParameter param2;
        public override void OnStart()
            param1 = Actor.As<AnimatedModel>().GetParameter("isWalking");
            param2 = Actor.As<AnimatedModel>().GetParameter("isRunning");

        public override void OnEnable()
            // Here you can add code that needs to be called when script is enabled (eg. register for events)

        public override void OnDisable()
            // Here you can add code that needs to be called when script is disabled (eg. unregister from events)

        public override void OnUpdate()
            if (Input.GetKeyDown(KeyboardKeys.W))
                isWalking = true;
                param1.Value = isWalking;

            if (Input.GetKeyDown(KeyboardKeys.Tab))
                isRunning = true;
                param2.Value = isRunning;

                isWalking = false;
                isRunning = false;
                param1.Value = isWalking;
                param2.Value = isRunning;

As you suggested, I took a sneak peek to the Output Log… Seems to be a problem with my machine, isn’t it?

The part about the Unrelieable GPU timer query is probably because you have a slightly older graphics card. Don’t worry too much about it, it shouldn’t cause any issues. For the next update, the warning will only appear once.

Regarding your code, does the output log say anything when you start the game? One thing I noticed is that in your animation graph, it says IsWalking (captial I), however in the code it says .GetParameter("isWalking").

Here is the output log when I start the game:

[ 00:17:29.850 ]: [Info] [PlayMode] Start
[ 00:17:29.865 ]: [Info] Changing editor state from FlaxEditor.States.EditingSceneState to FlaxEditor.States.PlayingState
[ 00:17:29.865 ]: [Info] Apply game settings
[ 00:17:29.905 ]: [Info] Collecting scene data
[ 00:17:29.905 ]: [Info] Saving scene Scene to bytes
[ 00:17:29.905 ]: [Info] Scene saved! Time 0 ms
[ 00:17:29.905 ]: [Info] Cleanup graph for scene 'Scene’
[ 00:17:29.905 ]: [Info] Unloding 1 lightmap(s)
[ 00:17:29.905 ]: [Info] Gathered 1 scene(s)!
[ 00:17:29.905 ]: [Info] Creating scenes
[ 00:17:29.905 ]: [Info] Loading scene…
[ 00:17:29.905 ]: [Info] Loading 1 lightmap(s)
[ 00:17:29.910 ]: [Info] Created graph for scene ‘Scene’ in 0 ms
[ 00:17:29.910 ]: [Info] Scene loaded in 5 ms
[ 00:17:29.925 ]: [Info] [PlayMode] Enter
[ 00:17:29.925 ]: [Info] Input = 00
[ 00:17:29.945 ]: [Info] Input = 0

I modified the .GetParameter(“IsWalking”), but nothing happens.

Thanks for your patience and help!!!

IIRC, Input.GetKeyDown is only true in the frame in which you pushed the key down. Input.GetKey is true as long as the key is pushed down. I guess you could try swapping one for the other.

Anyways, if that still doesn’t fix your issue, could you send me your project and I’ll take a look at it?

after some tests and adjustments, I solved the issue.
I think my error is the Physics type used for the Player. The Character Controller seems to have some problems…
As I changed it, using instead RigidBody, the script does perfectly its job. In the game start, my player is in Idle state, then as it moves forward, the animation switches to walking. If I push down Tab-key, the player runs. And viceversa, as I set up in the AnimationGraph.

About Physics component, I used for the ground plane a box collider, with a box mesh as child node.
How is it possible to perfectly scale the collider in relations with the box mesh?
I set the Transform of both with the same values, but the player before reaching the ground end starts falling througout space.

As long as you make sure to only translate/rotate/scale the parent (box collider), the children will also be transformed correctly (box mesh).

1 Like

Thanks for your reply!
Bye! :ok_hand: :wave:

1 Like