|Attention||Topic was automatically imported from the old Question2Answer platform.|
I wanted to change scene when i press a button, using a function from my GameManager Script. My GameManager Script was made to hold all my functions to prevent redundancy. My button is named “Start” and it has a script called “Start.gd” and inside is.
extends Button var GM = load("res://Scripts/GameManager.gd").new() func _on_Start_pressed(): GM.changeScene("res://Scenes/GameField.tscn")
Inside my GameManager is the function
func changeScene(Scene:String): var ret = get_tree().change_scene(Scene) if ret != 0: logError("Scene error#"+ret+". Could not change to Scene:\""+Scene+"\"")
Disregard logError it is just a func that writes error into an error file. The problem here is that if i wrote this code in my Start.gd it will work just fine but when i use it from GameManager.gd it cause the error “attempt to call function ‘change_scene’ in base “null instance” on a null instance”. How do I fix this? I have an inkling idea that maybe because the target node was different between the two scripts.(Forgive me I am still a student programmer)