My .play function says it's nonexistent

Godot v4.4.stable

Hey, I’m pretty new to programming, and I am making a game. It is going well so far, but I ran into a problem, trouble troubleshooting isn’t fixing. I have a transition set up that I can program to go to transition scenes, and I was trying to add it to my title screen, but when I programmed it to play, there was an error. I don’t know why this is because I haven’t had a problem with the other transitions.

Hi,

Your variable is set to an AnimationPlayer on ready. However, in _on_start_pressed, you set it to visible, which is a boolean. Since you variable isn’t typed, you can change it from an AnimationPlayer to a boolean.
Afterward, you call the play function, which would be valid for an AnimationPlayer, but now that it’s a boolean, such a function does not exist.

Try removing the instruction in _on_start_pressed, like this:

func _on_start_pressed() -> void:
    pass

And if that works, that means this is indeed the problem.


To type your variable, you can specify the type like this:

@onready var SceneTransitionAnimation: AnimationPlayer = $SceneTransitionAnimation2/AnimationPlayer

This would prevent you from doing mistakes without realizing it, as once a variable is typed, you cannot do anything you want with it, it’s more protected.
For instance, after typing your variable, Godot should not allow you to set its value to visible, as it would not be a valid type. Hope that makes sense, feel free to tell me otherwise.

Thanks! I will try it.

1 Like

Okay, so that kind of worked, but the problem is now that the play function works, I need it to play after I press the button. The problem with this is that I need the fade-out animation in the front of everything, which it already is. But when visibility is on, I can’t press the button, so I had to turn it off. I need a way to turn it back on when the button is pressed, then play the animation, then wait till the animation stops, and then the scene can change.

Maybe try:

func _on_start_pressed() -> void:
    SceneTransitionAnimation.show()

As @sixrobin said, you were overwriting the variable with the visible value in your original version, but I think what you want to do is call the .show() method on the animation player.

You could also do:

func _on_start_pressed() -> void:
    SceneTransitionAnimation.visible = true

What was happening in your code is, your script inherits from Control, which itself inherits a boolean visible value, I think from Node or possibly further up the object hierarchy. visible does indeed control visibility (and the .show() and .hide() methods can also be used to change it), but when you say foo = visible you’re setting foo to whatever boolean value visible currently has, and furthermore it’s using the value of visible from the script.

You want to affect the visible that’s owned by SceneTransitionAnimation, which means either you have to reference it explicitly (SceneTransitionAnimation.visible = ...) or you have to call one of the methods on the object (SceneTransitionAnimation.show()). Otherwise, you’re referring to the visible contained in $TitleScreen, since that’s where this script is attached.