How to access script of a scene right after instantiation?

Godot Version

4.2.2 stable


I’m trying to access script right after instantiation and says I’m in static so wth what can I do or what is the correct way?

this is where I’m calling the instantiation:

extends Node3D

func _ready():
	var instance = preload("res://Scenes/Player2.tscn").instantiate()
	var s = instance.get_script()
	s.SetCamera()	#E 0:00:00:0522 @ _ready(): Can't call non-static function 'SetCamera' in script.
  					#<C++ Error>    Condition "!E->value->is_static()" is true. Returning: Variant()
  					#<C++ Source>   modules/gdscript/gdscript.cpp:853 @ callp()
  					#<Stack Trace> @ _ready()

what is the correct way of accesing it’s script?

this is what I’m trying to call

func SetCamera():
	print("in camera")

if this works I can change it’s values later on
so it must not be static.

You call the functions in your instance

no from scene in mapRoot

and in there I call instance

and I’m trying to call function in instance that I’ve created

so maybe yes if you mean the last part. and no if you mean first part

getting the script is unnecessary

1 Like

that easy ohhhh, … thanks so much

1 Like