0 votes

I tried this but doesn't work.

    var sound = AudioStreamPlayer2D 
    add_child(sound)
asked May 22, 2019 in Engine by usurun (322 points)
edited May 22, 2019 by usurun

1 Answer

+2 votes

You must create a new node of the given class:

var sound = AudioStreamPlayer2D.new()
add_child(sound)
answered May 22, 2019 by kidscancode (17,776 points)

Thank you ...

What would be the name of the created node?
It just keeps returning null.

What is returning null? You really should include code and error messages (if any) with your questions. It saves a lot of time.

A newly created node is assigned an automatically generated name.

var sound = AudioStreamPlayer2D.new()
add_child(sound)
print(sound)

The result is @@2. If you want to assign a name use

sound.name = "NewName"

Thanks, I was writing it the wrong way.

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.