2
\$\begingroup\$

I need a reference for the game-object from another scene but the problem is that the scene object by default is off. So I thought that I should place its reference in another script and get a reference from it. But it will introduce me to a new script (third script) which means a new dependency. Now here is the triangle to solve the issue (which i don't like and posting here)

First scritp where the refrence is require

The actual refrence (Script/game-object) reside in a separate scene.

The reference holder

My consideration is that this is not the right way to do this job as its required dependency. How can i efficient and more professionally deal with it?

\$\endgroup\$
3
  • 1
    \$\begingroup\$ This sounds oddly complicated and probably has a simpler solution. Why is the object off? Why is it in a separate scene? Is there no manager in it's scene that controls it? \$\endgroup\$
    – Mars
    Commented Mar 3, 2020 at 9:06
  • \$\begingroup\$ Yes, you may be right! Let me tell you why it is off. Its a UI that I don't want to show to the user on-screen startup. Why it is in a separate scene. It's in UI scene which is separate from my model scene. \$\endgroup\$ Commented Mar 3, 2020 at 10:26
  • \$\begingroup\$ See also What is the proper way to handle data between scenes?. There the focus is on scenes loaded sequentially, where it looks like you're dealing with two scenes that are both active simultaneously, but some of the same techniques can apply. \$\endgroup\$
    – DMGregory
    Commented Mar 3, 2020 at 12:51

1 Answer 1

1
\$\begingroup\$

If this object belongs to a scene, I would consider the scene an object in and of it self. In other words, I would have a top level object with a SceneXManager, with references and/logic for the objects inside itself.

The SceneManager would be enabled, and the reference to the other object would be set via the inspector. Then it does not matter if the object you need is disabled or not.

\$\endgroup\$
2
  • \$\begingroup\$ You mean i should have a sceneManager script in the scene from where it will get the object? But I said in the question that it will create a dependency? which i don't think is the right approach. You want to develop a single script for reference handling? \$\endgroup\$ Commented Mar 3, 2020 at 10:29
  • \$\begingroup\$ @MuhammadFaizanKhan Think of it as an API to your new scene. In this way, you can limit what's easily visible and should be accessed. There may be better ways though! Take a look at what DMGregory linked \$\endgroup\$
    – Mars
    Commented Mar 3, 2020 at 12:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .