I’m working through designing a 3D rogue-like and I’ve completed the code necessary to generate a room in both the editor and at runtime. However I’ve only succeeded in making a single room, adding a second removes the first’s mesh from being drawn.
I know why, so I set to making my room generation internalized so that each room would be a single game object with its own Mesh and associated rendering components. However I’m not sure how to make the rooms into an actual object which I can instantiate, one that adds itself to the world. Instead, at the moment, I’m creating a GameObject and adding the room component to it. I know the component executes in the editor because of Debug.Log statements, and manually working out the vertex locations and triangle loops it all appears to be generating correctly, but no geometry appears.
The room object (RenderRoom) is a MonoBehavior type with RequireComponent entries for MeshFilter, MeshRenderer, and MeshCollider (though I make take the collider off). Generating new rooms does create empty game objects in the scene. They do have all three required mesh components, and appear to have a generated Mesh assigned to their respective components just as was working when I was able to make a single room.
The question, I believe, is how do I make my room into an object I can instantiate on its own, like a Cube from the GameObject menu let’s say (not necessarily does it have to exist in that menu, the Cube is just an example). Is it as simple as changing from MonoBehavior to GameObject, and then using Instantiate(…)?