- Home /
Is it possible to set a Mesh Filter's Mesh property to quad in code?
If you use the editor to create a 3D Quad Game Object, it adds a Mesh Filter with the Mesh set to Quad. If you add your own Mesh Filter Component, is it possible to (via code) set it's Mesh property to Quad and use the built in Quad Mesh asset?
If so, could someone demonstrate this hopefully very simple task?
Answer by HarshadK · Feb 03, 2015 at 11:36 AM
You can create a Quad gamaobject and assign its mesh to your mesh filter. Like:
// Create a guad game object
GameObject quadGO = GameObject.CreatePrimitive(PrimitiveType.Quad);
// Assign the mesh from that quad to your gameobject's mesh
GetComponent<MeshFilter>().mesh = quadGO.GetComponent<MeshFilter>().mesh;
This is what I came up with as well, but as a learning exercise, I'd like to do this without creating the entire quad primitive game object (which includes components I simply don't want/need).
Interesting. One can load a default shader with Shader.Find(""); I'm now also curious if there is a command that can load a Unity primitive mesh.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Changing the name of a project-asset in C# 1 Answer
How to active mesh renderer with a script C# 2 Answers
Reusing assets / performance question 0 Answers