- Home /
Is there any way to render a gameobject multiple times or do a per-hex outline?
Is there any way to render a gameobject multiple times without cloning a prefab repeatedly (which wouldn't be anywhere near as efficient as instancing, I expect) or do a per-hex outline without doing so?
What I'm trying to do is this: I have a bunch of hexes and my intention was to have empty hexes have an outline. So I made a model and texture for that. The buildable area, however, is 2^18 hexes currently. If worst comes to worst I can just make enough of these 'empty space outline' objects to go in the visible area and place them there, then either relocate them as the screen is scrolled, or destroy and recreate them (likely less efficient but easier). (A problem would obviously arise if the user scrolled way out, as more and more would be required, but I could just turn them off at a particular zoom or something)
I'm hoping there's a more efficient way, however. (I've used instancing in XNA previously, and HLSL, but the shaders used in Unity look completely different to me and I'm not sure what's going on in them - and I seem to be locked out of all the useful features due to not having the pro version, so I've avoided messing with the shaders and ignored all the pro-only classes for now)
This is my first question because until now I haven't run into anything I couldn't figure out myself or by googling.
Answer by Julien-Lynge · Feb 25, 2013 at 04:22 AM
As you mentioned, shaders would be one way to do it. I'm not sure about your issues with shaders - I didn't think there was anything Unity-Pro-only there, but I could be wrong. As a quick rundown: Unity has 'ShaderLab', which is code that wraps around HLSL/GLSL/Cg shaders. Unity also has its own 'surface shaders', which are just a way to write lighting calculations and have Unity generate the appropriate vertex/pixel shaders. If you're used to HLSL, you shouldn't have any trouble jumping to Cg, which is what the vast majority of (non-surface shader) Unity examples are written in. I suggest checking the Unify Wiki.
However, rather than go to all the trouble of doing it in shaders, you can probably do it pretty easy with meshes. Keep in mind that a single mesh can hold 65536 vertices, so if each hex tile were, say, 24 vertices, you could hold 2730 of them in one mesh / game object / draw call. Just go into your favorite modeling program and create an array from your hex tile, making sure that it doesn't create a new material for each copy, and you're set.
Your answer
Follow this Question
Related Questions
How to get good looking graphics in UNITY 3D.. 1 Answer
Evaluation question 1 Answer
is using OnPostRender to draw textures Pro only? 3 Answers
How Do I Make The "Solar Outline" Effect? 0 Answers
2D Reflections with URP 0 Answers