3
\$\begingroup\$

I am a complete beginner in Unity and, after having search for a while, I am still not sure if it is actually possible to achieve what I would like to do.

My goal is to have a game where the screen is split in 4 regions where:

  • in the first there is a 3D scene;
  • in the second a 2D representation of the first one (a sort of map);
  • in the third a 2D scene that has nothing to do with the previous ones;
  • in the fourth a "sort" of UI (i.e. there is no moving object even if it requires an ongoing user interaction).

Interactions of the user in the 1st, 2nd and 4th happen via mouse, in the 3rd with the keyboard.

How can I achieve that?

\$\endgroup\$

1 Answer 1

6
\$\begingroup\$

This is easy to achieve with viewports.

Inside the Inspector settings on the Camera component, you'll find a section labelled "Viewport Rect" that defines the rectangle on screen that this camera should render to.

The default value is {x: 0, y: 0, w: 1, h: 1} which means "start in the bottom-left corner (0, 0) and occupy 100% of the width and height". Changing those 1s to 0.25 would make the camera render to just one quarter of the screen, and changing the 0s would move where that quarter-screen pane sits within the wider screen (or window).

So: give each "scene" you want to render its own camera, with different viewport rectangles each. That will get your split screen rendering taken care of.

You can author each of these four panes in a separate scene file if you like, and when you start the game, load all four scenes together using LoadSceneMode.Additive to stack the scenes up in the current state, rather than unloading the previous scene before loading the next.

This overlaps all scenes in a single world coordinate space, so you'll want to author them so they don't interfere with each other. I'd recommend placing them in distinct areas of the world coordinate system (not too far from the origin), so that when you work with them in the scene view while testing you can see and select content from each one without confusion. You can also use Layers to filter content, so cameras in one scene don't see content loaded from another, and so physics objects in one don't interfere with another (using the Layer Collision Matrix).

You can communicate between these scenes with a static manager script. Or you can author some of them that need to be tightly linked (like the 3D scene and its 2D map) in a single scene file to make it easy to wire up references between them (though you can still save each version of the environment as its own prefab if you also like working with them as separate files at other times).

You could even make this with a single copy of the 3D environment rendered from two views by two cameras, using layer and shader tricks to make the 2D map camera render it the way you want without needing to author a whole second copy of the space. This can save you from bugs that arise when you change something in one version of the scene and forget to make exactly the same change in its counterpart.

Or, another way you can attack this, since all your other "scenes" are 2D, is to use the UI system. You can render your 3D scene to one corner with a viewport as explained above, then put your other four views into a UI Canvas set to Screenspace Overlay mode, so it draws over the whole screen after all cameras have rendered.

\$\endgroup\$
1
  • \$\begingroup\$ thank you very much for your great and detailed answer. \$\endgroup\$ Commented Oct 28, 2022 at 16:06

You must log in to answer this question.

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