[Studio Beta] Introducing State Machines and Luau Expressions for Animation Graphs

Hi Creators,

Today, we’re releasing State Machines and Luau Expressions as a Studio beta for the Animation Graph Editor, which came out of beta in July.

State machines embedded in AnimationGraphs let you describe the flow of animation through various states that aren’t driven by Gameplay state (via explicit parameters). In a sword combo, a character can go from Swing 1 to Swing 2, but it can’t go from Idle directly to Swing 2 unless you wire a transition between them.

Before this update, the graph didn’t track which state a character was in. The existing Priority Select node checks all of its conditions every frame, so a check meant to move from Swing 1 to Swing 2 could also fire while the character is still in Idle. To avoid that, you had to track the state yourself in a Luau script and pass it to a Select node. With the State Machine, you can lay out the states and the transitions between them directly in the graph.

image2

Set Up States and Transitions in the Graph

Add a State Machine node and open it. You’ll see its states and the transitions between them, with one state marked as Entry. A state can be any node in the graph that outputs a pose.

For each transition, write the condition as a Luau expression over your graph parameters, such as Speed > 5 (expressions are covered in the next section), or set the transition’s Wait For to Finished to transition when a state finishes, and set a Length and Curve for the blend. Transitions wired from the (Any) state can fire from every other state in the state machine (e.g. a transition from (Any) to Holster when IsEquipped == false lets the character put the sword away mid-combo). When two transitions could fire on the same frame, the one with the higher Priority wins. Each priority value has to be unique within the state machine.

Your script still sets the parameters, but it doesn’t need any transition logic:

RunService.Heartbeat:Connect(function()
    local speed = humanoid.MoveDirection.Magnitude * humanoid.WalkSpeed
    animationTrack:SetParameter("Speed", speed)
end)

Write Parameter Math in One Node

An expression is a line of Luau that sets a node property or a transition condition. Before, you’d compute the value in a script and pass it in. For example, this expression turns movement speed into a blend weight between 0 and 1:

math.clamp((movementSpeed + 0.5) / maxSpeed, 0, 1)

image1

Each expression is parsed once when the graph loads and is evaluated when a node uses it. Expressions are serialized and published with the graph asset instead of living somewhere in a script.

To add an expression, drag a wire from a property pin and choose Expression, or use the Insert menu.
image5

Supported Syntax:

  • Arithmetic: +, -, *, /, ^, %, and //
  • Comparisons, plus and, or, and not
  • Conditional statements: if speed > 10 then "sprint" elseif speed > 2 then "run" else "idle"
  • The math library, such as math.clamp(), math.sin(), and math.max()
  • Vector3.new() and member access like moveDir.Magnitude or position.X
  • String concatenation with ..
  • Multi-line expressions with local variables and non-nested if/else statements

Expressions are currently limited to the above syntax and don’t support loops, function definitions, tables, require(), method calls like obj:Method(), libraries other than math, or DataModel access. Use a script for anything else. While previewing the graph in the Graph Editor or play-testing, If an expression fails to parse or evaluate while you preview or playtest, you’ll see an error in the Output window.

Improvements Since Full Release

We’ve also shipped these fixes since July 15:

  • Server Authority: Graphs use less bandwidth. Large graphs are less likely to overflow the attribute size limit or print errors when bound with BindToSimulation().
  • Blend Nodes: Blend2D accepts negative Y values, and collapsed Blend2D nodes resize correctly. Blend maps now render the first time you open them.
  • Sequence Nodes: Sequence and Random Sequence support When = BeforeFinished. Use this setting to transition from the end of the active input to the start of the next input.
  • New Node Type: The One Shot node plays a one-shot pose on top of a base pose, then resets. Use Trigger parameters so they reset automatically. More details here.
  • Editing: Duplicating a node no longer copies its connections. Graphs no longer load with disconnected nodes, and angle properties display in degrees.
  • Reset: The toolbar Reset button resets graph state during playback.
  • Create Animate Script: No longer generates an empty script.
  • View > Organize: Lays out your nodes automatically.

Known Issues

  • You can’t manually set a state or trigger a transition from the editor.
  • Adding parameters will always add a green parameter node to the graph even if you don’t wire it to something. This will be fixed soon.

What’s Next

This is an early beta. We’ll fix bugs and adjust the design based on what you report before these features move to full release.

Resources

Please post bug reports and graphs you’ve built in the replies. Let us know if you have any questions or feedback. Thank you.

FAQs

Click to expand

Q: Can I use State Machines and Expressions in live games during the beta?

A: No. They only work in Studio at the moment.

Q: Does a State Machine replace Humanoid states?
A: No. State Machines are for animation states, such as the steps in an attack combo or a reload animation. Gameplay states like jumping or dying still come from the Humanoid or your own scripts, and you can pass them into the graph as parameters if your animations need them.

Q: Do I still need a script?

A: Yes, to set parameters from gameplay. Transition logic and parameter math can move into expressions in the graph.

Q: Can an expression read properties from my character or the workspace?

A: No. Expressions only read graph parameters. Use SetParameter() to pass anything else in.

Q: Why does the higher Priority win?

A: It matches existing Roblox conventions like Enum.AnimationPriority, where a higher number means higher priority.

Q: Should I stop using Priority Select?

A: No. Priority Select still works. A state machine is the better fit when a transition should only apply from certain states.

150 Likes

This topic was automatically opened after 10 minutes.

1 Like

Sweet baby builderman praise the LORD! You champions simply don’t stop delivering.

Can we get a bugfix pass on the AGE next?

Also clamp a blend node’s position to its bounds… We can do this ourselves!

19 Likes

It is the most wonderful thing I have seen today.
Emerald

25 Likes

:clap: now remove enforcement ban! because its ruining roblox

6 Likes

Not the place to preach truth, this team has no ability to waver the enforcement ban.

30 Likes

This sounds absolutely incredible! Can’t wait to start using it.

2 Likes

is the state machine demo public?
nevermind Animation Graph State Machine Simple Demo | Play on Roblox
we dont have animation permission

1 Like

For the past few weeks I’ve been implementing a fighting game combat system in Unity. Mostly naive approach at first. Finding time for everything is difficult, but that aside…

It’s nice to see Roblox Studio catching up in capabilities.
Creators today will be far more prepared for topics like this across engines. It makes more transferable skills while pushing the engine to allow what it wasn’t so capable of before.

Hopefully with this we can see more combat focused games thrive.

2 Likes

I’m surprised Roblox hasn’t gotten sued because of these false enforcement bans. Imagine if it happened to a developer who made a living off of developing on Roblox. Roblox should remove as it’s done more harm then good.

You can’t sue a company for banning you

(especially with the current and new terms of service)

Roblox reserves the right, in its sole discretion, to terminate or suspend (i) your Account and (ii) your right to use and access the Roblox Services, including by suspending or terminating any alternate account(s) you create or have created.

(User Terms, Section 2e)

2 Likes

We’re working on getting the right animation permissions for the state machine example in that demo.

2 Likes

I’m saying if it’s because of a false automated ban. If it’s a ban cause u broke the rules then yeah

1 Like

The animation permissions have been updated for the demo place in the state machine documentation. Enjoy!

1 Like

Not the place to do this. And honestly, if shedletsky himself keeps having his games getting taken down by AI, then they already know how bad their system is.

In relation to this update, this animation editor looks cool, might try it out. Looks complex with all the options and arrows lol.

5 Likes

THANK YOU

Animation Graph’s are the future of organizing any project!!
It’s like Packages, but for animations – BUT BETTER.

less code; less asset id hassle
try if it you havent

1 Like

even false bans aren’t able to be sued for, any company reserves the right to ban whoever they want for whatever reason as long as it’s not discriminatory

2 Likes

Wait, this one’s actually big
And I really mean it
I used to burn neurons trying to tween parts between animations

1 Like

We got colored folders, tunable collision fidelity, if local = x then, ui gradients+++, collision subscribing, rotations clip descendants, and new animation graphs methods in the span of 3 weeks ???

And soon enough well get surface appearance resample mode + layers ???

Roblox staff please continue on this path you’re doing so great :sob:!!! This is beautiful

3 Likes

I just learned about them recently but i can’t find any tutorial videos about them :frowning:

1 Like