How Build a SampleLibrary in a global script?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By tiernich
:warning: Old Version Published before Godot 3 was released.


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?

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


Daniel Lewan | 2016-05-25 09:04

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?

tiernich | 2016-05-25 13:27

:bust_in_silhouette: Reply From: Daniel Lewan
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

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?

tiernich | 2016-05-28 14:36

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():

Daniel Lewan | 2016-05-28 22:29

thanks man! this works!

tiernich | 2016-05-29 04:09