- Home /
Procedurally generate icon textures
My game features procedurally generated parts/items and I would like to be able to display icons of these parts in the game's inventory view, which is a UI over top of a 3D scene. For this, I need to be able to programmatically set up a camera, generate the part, have it render to a texture, and keep that texture in memory for later use.
How do I do this in such a way that the part is never seen? I don't want random parts popping into the world every time a new icon is needed, and I don't want the other parts of the world visible in the icon texture. Hoping there is a more graceful way than just doing it really far away.
Answer by Eno-Khaon · Mar 25, 2018 at 09:12 PM
You can utilize Layers to get the effect you're looking for. Generate a camera which only views objects on a specific layer and place those objects on that layer. Then have your main camera ignore the same layer and you're good to go.
Some useful reference points for setting up Layer Rendering/Camera Culling through scripts:
Camera.cullingMask
"How to compute camera culling mask via script to show two layers"
"How to change if layer is rendered by camera in script?"
A word of caution, however: Make sure the object you're taking the snapshot of doesn't have a collider and/or won't *physically* interfere with other nearby objects you don't intend for it to.