godotengine / godotengine/godot

Cannot use class names in AnimationTree StateMachine's advance expression box

Open
#88,489 0 comments 0 reactions 0 assignees View on GitHub
discussion needs testing topic:gdscript
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

Reproducible in : Godot 4.2.1

### System information

Linux Mint 21.3 Cinnamon 6.0.4

### Issue description
Edit 21.04.2024: The issue has nothing to do with *custom* classes, using any class name in the advance expression box will not work.
`var v = Node.NOTIFICATION_READY` Set a variable to any random enum from any class.
`v == Node.NOTIFICATION_READY` Putting this in the advance expression box will not advance.

Original post:

I have a character that's script extends a custom class that i made. A 'state' variable in the custom class is used to control the animation tree, via the advance expression property. (see below)

Custom class script:
```
class_name MyCustomClass
extends Node

enum State {
IDLE,
JUMP,
}

var state = State.IDLE
```

Character script:
```
extends MyCustomClass

func _process(_delta):
if Input.is_action_just_pressed("ui_accept"):
state = State.JUMP

# Called by the jump animation
func print_jump():
print("JUMP")
state = State.IDLE
```

Putting `owner.state == owner.State.JUMP` in the animation tree's advance expression box works, but `owner.state == MyCustomClass.State.JUMP` doesn't, even though it should. MyCustomClass gets syntax highlited in the advance expression box, indicating that it is recognized as a class name, but the transition doesn't advance.

edit: adding a `static var ADVANCE = true` variable into MyCustomClass and setting the advance expression to `owner.ADVANCE` will make the transition travel, but `MyCustomClass.ADVANCE` will never travel.

(I don't know what exactly is the issue, please change the title that describes it better. Thank you)
edit: added some extra info

### Steps to reproduce

Please see minimal reproduction project. Currently the advance expression is `owner.state == owner.State.JUMP` and it works, but change the advance expression to `owner.state == MyCustomClass.State.JUMP` and it will stop working.

According to my testing, in the advance expression box, trying to access any variable like `CustomClass.my_variable` won't work.

### Minimal reproduction project (MRP)

[AdvanceExpressionTest.zip](https://github.com/godotengine/godot/files/14322134/AdvanceExpressionTest.zip)

Contributor guide

Open the contributing guide

Research direction

Start with the attached AdvanceExpressionTest.zip minimal reproduction and inspect the AnimationTree StateMachine advance-expression behavior. Compare the working owner.State expression with the failing MyCustomClass.State and MyCustomClass variable expressions. Done means class-qualified names evaluate correctly in the advance expression box and the reproduction transition advances as expected.

Written by the indexing model from the issue text.

Assessment

Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.