I’ve got a UI Canvas with a couple children.
- One of these children covers the screen, and has a bunch of its own children with interesting content (buttons, text, etc.) that collectively make up most of what’s currently visible.
- Another top-level child of the Canvas is in front of the first object, and partially occludes it.
I’d like to get a render (to a texture) of just the first object (and its children) without the occluding object in front–i.e. what the entire screen would look like if the front, occluding object were removed.
The ideal solution should also meet the following criteria:
A. Invisible to the user (doesn’t change what actually gets displayed on the screen for the player to see)
B. Does not make any particular assumptions about how object #2 works or how the rest of the object hierarchy is set up (e.g. I’d prefer not to require that object #2 be placed in a special layer)
C. Completes in the same frame (a solution with a 1-frame delay on results would still be useful, but is not ideal)
Some options that have occurred to me:
I could disable object #2, wait a frame, take a screenshot, and re-enable object #2. This accomplishes the main goal but fails ALL of my secondary criteria.
I could place object #2 in a different layer, set up a second camera that ignores that layer, and wait while the second camera renders the screen (without object #2) to a texture. This meets criteria A but fails B and C.
Anyone have a better suggestion?
Presumably there is some code somewhere inside of Unity engine that “knows” how to render a specific object or objects without rendering the rest of the world, but I don’t know if that’s accessible to a game developer in any way that’s useful for this particular problem.