What would the logic for a character select screen in Godot be and what lines of code would be extremely useful?

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

So I want to make a character select screen where literally all that happens is that a sprite of a character gets swapped with a different texture once you hit a button on the character select screen, I have tried messing around with button nodes to no avail. I could not find a tutorial on how to make a 2D character select screen. If someone can help me by giving me the basic logic of and some code that can help make a 2D character select screen, then I would be most thankful. Or you can share a tutorial on how to make a 2D character select screen with me, that works just as well. To explain what I want, I want to press the tab key that brings up a menu that contains buttons, and once you click on those buttons the texture on my sprite gets swapped with a different texture. I have gotten the menu to work, but once you click on a character button, it does nothing and it kinda just crashes the game. So I would like to start off with fresh code and not share my code and add on to it as it seems to be causing issues.

:bust_in_silhouette: Reply From: magicalogic

I don’t know of how to create the whole scene but here is how to change the texture.

var texture = load("res://path/to/your/texture.png")
$Sprite.texture = texture

I did that but I now keep getting the error “Invalid set index ‘texture’ (on base: ‘null instance’) with value of type ‘StreamTexture’.” Here is what the code looks like(also the code under the func value is indented, its just I couldn’t do that on phone):

tool
extends Button

export(String, FILE) var next_scene_path = ""

func _on_Button_button_up() -> void:
get_tree().change_scene(next_scene_path)
get_node("res://src/Actors/BeepoActual.tscn")
var texture = load(res://Assets/SPACE FOX.png")
$Sprite.texture = texture

func _get_configuration_warning() -> String:
return "next_scene_path must be set for the button to work" if next_scene_path == "" else ""

AshTheKindra | 2021-06-04 15:12

Are you sure you have the Sprite in your scene and it’s name is Sprite?

magicalogic | 2021-06-05 05:04