The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes


I have one Global Script SamplePlayer2D and some sounds.smp

and i search how to use SampleLibrary, get_sample, etc... but dont have succeed

How can i make a Sample Library and load samples to it with gdScript?

in Engine by (429 points)
edited by

I don't really understand your question. Do you want to have global sample player?
You can autoload (Project Settings > AutoLoad) scene that contains sample player (for example samples.tscn) and use it like this


Thnx for the answer! Yeah, i now how do this :).
Let me explain better. Imagine that in this samples.tscn, you want to have a script to load the files, how do it? How to make a Sound Library(just samples, not stream) with gdscript?

1 Answer

+3 votes
Best answer
var sample = preload("res://sounds/sound.wav") # you can use load() instead

var lib =
lib.add_sample("name", sample)

var player =

Related docs Sample | Sample Library | Sample Player 2D

by (373 points)
selected by

Hi. thanks for the answer.

This works for samples, now i have tried apply this for stream and have no success

extends StreamPlayer

var Song = load("res://Sounds/Jobro.ogg") # you can use load() instead
var player =

func _ready():

this runs fine, with an empty error on without any info...
i have tried some tutorials and things on the net but...
can you help me on this?

From your snippet I guess you attached script to StreamPlayer node thus your code should look like this:

extends StreamPlayer

var Song = load("res://Sounds/Jobro.ogg")

func _ready():

There is no need to create new StreamPlayer with var player = if you already added one using editor. You can create StreamPlayer from code like this:

extends Node # or anything else
var Song = load("res://Sounds/Jobro.ogg") 
var player =

func _ready():

thanks man! this works!

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 Frequently asked questions and 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 [email protected] with your username.