Using a node from a different scene

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

Hi - to put it simply, I’m stumped. I’ve looked online for the same or similar problems, but none of the answers work. What I want to do is have a node follow a node from another scene without instancing it in the current scene. What are some ways I could do this?

:bust_in_silhouette: Reply From: kidscancode

If you haven’t instanced the scene, then it’s just a file sitting in the project folder and it doesn’t “exist” in game.

When your project is running, there is only one “current scene” - the nodes running in the current scene tree. You can’t follow a node that isn’t part of the scene tree.

Ok, but I don’t want there to be another player. Is there any way to instance a node without making a duplicate in the main scene?

ThreeSpark | 2018-07-29 18:43

I don’t understand - why would there be two players? What is this “node from another scene” that you’re talking about?

The idea is to separate the different game objects into their own independent scenes (a scene being a collection of nodes). Then you can instance as many of them as you like.

For example, let’s say I have two scenes:

  1. a player scene, containing the player code for moving, animation, etc.
  2. an enemy scene, with code that makes it chase a target (the player)

Then, in my main scene, I add one instance of the player, and several instances of the enemies.

kidscancode | 2018-07-29 18:48

Nevermind - I solved my problem. I thought that by instancing my player in the scene it would add another player when I instanced the player in my monster scene. I was wrong.

ThreeSpark | 2018-07-29 18:55