[Solved] Trying to understand Godot's Logic: modifying all instances of a scene

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


I usually use Unreal Engine to make games (because I’m making VR games). I love its blueprint logic and how, by just casting to the main blueprint of an object, you can modify all the instances of that blueprint, whatever the current level is.

So there is my problem:

I made arrows, when you click on it, the camera moves to the direction that the arrow is pointing.

There are 4 arrows, the 4 are scenes that I instantiate multiple times in my level scene so I don’t have to rewrite the code for all of them.

The camera is a scene of a node2D with a camera as child node. I move the node2D to get a smooth camera movement. I just instantiate the scene in my main level so I don’t have to rewrite the code in all my levels.

Lets imagine the camera movement function and click input handle is done and ready. I just need to call the function to make it work, but I don’t know how and where.

I don’t want it to be linked to the current scene, I want it to work everywhere from the moment an arrow and a camera is on the scene.

I tried to use get_node(“path of the “main” camera scene I use to instantiate in all the other scenes”) but I got a null reference.

I tried with a signal, but error: cannot connect to a null instance.

I also tried to load the script, the function can be called, debug prints show up, but the camera is not moving. The function works by calling it on the ready function of the camera script.

var camera = load("res://PlayerPosition.gd").new()

I’m confused. I’m sure it’s just because I want Godot to work like UE4 too much, but I’d love to find how to do it in Godot so my arrows and camera works in any scene and I don’t have to copy/past everytime I want to make a new level.

Thanks in advance for your help!

Did you add the camera to scene tree?

var camera = load("res://PlayerPosition.gd").new()

Dlean Jeans | 2019-06-15 16:21

Doing so will create a new instance right? Because an instance of my character is already in the scene and I want to move this one.

I already have a CharacterPosition scene which include the node2D and the camera. I dragged and dropped the scene in my level scene to instantiate it.

NekiCoule | 2019-06-15 17:02

:bust_in_silhouette: Reply From: NekiCoule

I was such a dummy.

Now I know, that you can use paths in other scenes script to make it work anywhere, like so:

func onClick():

Case close, sorry for bothering and overthinking so much! Learning a new engine ain’t easy that’s for sure!