Pregunta

So I'm using a CustomEditor setup to make a Spawn Point manager. I've got it setup to add spawn points in a scene (let's call it Room 1), no problems there. What I need to do next is load up a different scene (Room 2) and make a door interact reference a spawn point from Room 1. I have all parts of the equation setup except for how to get a list of spawn points in Room 1 while I'm editing the Room 2 scene.

Is there a way to call up a query of the values setup in an object in Room 1 scene while I'm editing Room 2 scene? Keep in mind this is in the editor/inspector, not while the application is running, so I don't think player prefs and DontDestroyOnLoad will help here.

Any thoughts? Thanks!

¿Fue útil?

Solución

Is there a way to call up a query of the values setup in an object in Room 1 scene while I'm editing Room 2 scene?

No, you can't. The editor let you open one scene at the time. You can consider different scenes as different worlds. You can add the content of a scene to the current opened scene, using EditorApplication.OpenSceneAdditive. Btw this isn't useful for your case, since the object of the scene added are copied inside the opened one.

If you need to share objects between scenes you have 2 ways to do that:

  1. Use a Prefab for your SpawnPoint Manager, if your Component is attached to a GameObject.
  2. If you don't want/can use a GameObject to store your SpawnPoint Manager (I don't think this is the case), you may consider using AssetDatabase. Basically you can store inside it every serializable class derived from ScriptableObject.

What I would do in your case is, more or less, the following:

  • Create an empty GameObject with attached a Component called SpawnPointManager.
  • Create a Prefab from the created GameObject.
  • Put in all scenes a Prefab instance of your manager.
  • Eventually define a custom Editor for modify your SpawnPointManager Component from a custom inspector

Since all your Prefab instances are linked to the same Prefab, even if they are in different scenes, basically the share the same object (accessible from the inspector). So if you modify the prefab it self (or an instance of it and apply the modification back to the linked prefab), all your prefab instances (even in the different scenes) will see the modifications and will update accordingly to the linked prefab.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top