Init class without scene to handle Input?

zell2002zell2002 Posts: 3Member

I've been thinking of building a Controller class to handle/process all input for my characters ingame.
Is this possible? I have this in my character script:
var controller = load("res://controller.gd").new()
_init() gets called, and i have:
`
set_process_input(true)
set_process(true)

func _process(delta):
print(delta)

func _input(event):
print(event)
`
These 2 funcs dont get called
Do these funcs not get called if they arent connected to a scene?

Also,I would need this Controller class to be called before my scene scripts get called - is this possible?

Maybe I am over thinking all this and my controller logic should just be in my Character class - i just thought this would be a good way of handling it.

Any information would be appreciated

Answers

  • AvencherusAvencherus Posts: 49Member

    Yep, those things don't work until they're part of the scene tree.

    Other alternatives are using a singleton, adding the controller as a child, or using the processing of the object to forward calls to methods in the controller.

Sign In or Register to comment.