How to get audiostreamplayer2d to play in an instanced scene

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mikemorton

I have a scene that has turrets that fire at the player and uses the audiostreamplayer2d to attenuate the volume depending on how far the player is from the turret. This scene works fine. I’ll call this scene A.

I want this scene to be instanced into another scene (one that skins the tileset, adds minimap, adds HUD etc.) I’ll call this scene B. Everything about scene B functions except the audiostreamplayer2d does not play at all. There are other regular audiostreamplayer (non-positional) that work fine in scene B (instanced from scene A).

Is there some information about the player position that scene B is not receiving from scene A?

I’ll put the full script for scene B below, but the majority of it has to do with the minimap. My thinking was that
func _ready():
level = load(“res://scenes/levels/crust/Level3_8x8_16_256.tscn”).instance()
was all the code that godot needed to bring everything over from scene A. Any help is appreciated!

extends Node2D

const CAMERA_ZOOM = 1

var level = null
var mm = null

func _ready():
level = load(“res://scenes/levels/crust/Level3_8x8_16_256.tscn”).instance()
mm = level.get_node(“Minimap”)
level.remove_child(mm)
$MinimapContainer/MinimapViewport.add_child(mm)
mm.flip_v = true
mm.position = Vector2.ZERO
level.name = “Level”
$WorldContainer/WorldViewport.add_child(level)
$MinimapContainer/MinimapViewport/Camera2D.zoom = Vector2(CAMERA_ZOOM, CAMERA_ZOOM)
var prng = RandomNumberGenerator.new()
for n in level.get_children():
var tm = n.get_node(“TileMap”)
if tm != null and tm is TileMap:
tm.scale = Vector2(1, 1)
tm.cell_size = Vector2(64, 64)
tm.tile_set = load(“res://sprites/TileSets/CrustTiles.tres”)
for x in range(32):
for y in range(32):
var fx = tm.is_cell_x_flipped(x, y)
var fy = tm.is_cell_y_flipped(x, y)
var ft = tm.is_cell_transposed(x, y)
var ix = tm.get_cell(x, y)
var variations =
if ix == 12:
variations = [ 12, 40 ]
var variations2 = [ 12, 40, 41 ]
if (tm.get_cell(x + 1, y) in variations2 and tm.get_cell(x - 1, y) in variations2 and tm.get_cell(x, y - 1) in variations2 and tm.get_cell(x, y + 1) in variations2):
variations = [ 41 ]
fx = false
fy = false
ft = false
elif ix == 13:
variations = [ 13, 39 ]
elif ix == 15:
variations = [ 15, 38 ]
elif ix == 16:
variations = [ 16, 37 ]
elif ix == 17:
variations = [ 17, 33 ]
elif ix == 18:
variations = [ 18, 32 ]
elif ix == 21:
variations = [ 21, 36 ]
elif ix == 23:
variations = [ 23, 34 ]
elif ix == 24:
variations = [ 24, 35 ]
else:
variations = [ ix ]
tm.set_cell(x, y, variations[prng.randi() % variations.size()], fx, fy, ft)
update()
pass

func _process(_delta):
var player = level.get_node(“Player”)
assert(player != null)
$WorldContainer.get_material().set_shader_param(“reversing”, Input.is_action_pressed(“Time_Reverse”) and player.time_reversal_left > 0)
$MinimapContainer.set_position(Vector2(get_viewport_rect().size.x - $MinimapContainer.get_rect().size.x / 2 - 16, 16))
# If this fails, it means you didn’t put the player in the level you specified
var pos = ((level.get_node(“Player”).get_global_position() / 32) - (mm.texture.get_size() / 2))
$MinimapContainer/MinimapViewport/Camera2D.position = pos
$HUD/CoinLabel.text = str(player.coins)
$HUD/KeyLabel.text = str(player.keys)
$HUD/TimeReversalBar.set_size(Vector2(player.time_reversal_left * 1820 / player.MAX_TIME_REVERSAL, 40))
pass