- Home /
How would I render meshes in the prefab stage from a script?
I would like to know how to use graphics.drawMeshInstancedIndirect() in the prefab stage. I wrote a sprite rendering engine for DOTS that uses that function and need to render data in the prefab stages to make prefab editing easier. Thanks!
Answer by enerology · Aug 04, 2020 at 07:06 AM
Here is the solution:
 public Material material;
 public Mesh mesh;
 
 public void OnEnable()
     {
         SceneView.duringSceneGui += updateScene;
     }
 
 public void updateScene(SceneView sceneview)
     {
         if (material != null)
         {
             Graphics.DrawMesh(mesh, Matrix4x4.TRS(new Vector3(0, 0, 0), quaternion.identity, new Vector3(1, 1, 1)), material, 0, SceneView.lastActiveSceneView.camera);
         }
     }
 
 public void OnDisable()
     {
         SceneView.duringSceneGui -= updateScene;
     }
You might want to add
-#if UNITY_EDITOR
//Code To Disable Here During Build
-#endif
if you are building the project as SceneView uses "Using Unity.Editor".
Your answer
 
 
             Follow this Question
Related Questions
How do I programmatically assign a GameObject to a prefab? 6 Answers
Viewpport for Custom Editor 1 Answer
How to modify prefab permanently via script. 0 Answers
Editing prefab fields from custom editor that are not automatically serialized 0 Answers
How to provide undo for EditorScript changes to a prefab? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                