0 votes

I have a PackedScene that loads an AnimatedSprite Scene playing Animation 1.
I want PackedScene, however, to play Animation 1, but after a while changes to play Animation 2;

I tried the basics with PackedScene.play("Animation2") function, but returned saying that it is a non-existent function in base PackedScene.

What is the best method to do this animation change in an AnimatedSprite from a PackedScene?

Thanks guys

in Engine by (165 points)

1 Answer

0 votes
Best answer

Hi lucasfazzi,
PackedScene is a resource mainly used to have a scene loaded that isn't used yet. If you use your scene you should instance it like this:

export (PackedScene) my_packed_scene = preload("res://Whatever.tscn")

func some_function():
    # create a new instance of the packedscene
    var new_whatever = my_packed_scene.instance()

    # if the root node of the packed scene is the Animationplayer
    new_whatever.play("Animation1")

    # otherwise
    new_whatever.get_node("AnimationPlayer").play("Animation1")

    # add the newly created "node" as a child in your running scene
    add_child(new_whatever)

Hope it helps, good luck!

by (756 points)
selected by

Hi Jowan;

Thank you for clarifying;

Worked as well.

Thanks

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories