Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by dissidently · Mar 07, 2011 at 05:14 PM · verticescreatepolygontris

how to: create a four vertex, two tri square polygon in Unity Editor or Script?

The plane object has WAY to many tris/verts for what I want. And I can't manipulate the verts. Or delete some of them.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yoyo · Mar 07, 2011 at 06:35 PM 0
Share

I've had that issue as well -- the plane prefab is (I believe) 10x10 verts, and also 10x10 units big. I found myself wanting a 2x2 quad at size 1x1, so I can look at the scale to see how big the thing is. I used procedural mesh creation to solve this, similar to Statements example.

4 Replies

· Add your reply
  • Sort: 
avatar image
8
Best Answer

Answer by Statement · Mar 07, 2011 at 05:51 PM

You can create a new Mesh like so:

 using UnityEngine;
 
 [RequireComponent(typeof(MeshRenderer)), RequireComponent(typeof(MeshFilter))]
 public class CreatePlaneMeshExample : MonoBehaviour
 {
     void Start()
     {
         GetComponent<MeshFilter>().mesh = CreatePlaneMesh();
     }
 
     Mesh CreatePlaneMesh()
     {
         Mesh mesh = new Mesh();
 
         Vector3[] vertices = new Vector3[]
         {
             new Vector3( 1, 0,  1),
             new Vector3( 1, 0, -1),
             new Vector3(-1, 0,  1),
             new Vector3(-1, 0, -1),
         };
 
         Vector2[] uv = new Vector2[]
         {
             new Vector2(1, 1),
             new Vector2(1, 0),
             new Vector2(0, 1),
             new Vector2(0, 0),
         };
 
         int[] triangles = new int[]
         {
             0, 1, 2,
             2, 1, 3,
         };
 
         mesh.vertices = vertices;
         mesh.uv = uv;
         mesh.triangles = triangles;
 
         return mesh;
     }
 }              
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yoyo · Mar 22, 2011 at 11:35 PM 0
Share

If I procedurally create a $$anonymous$$esh in the editor, then turn its game object into a prefab, the mesh is gone when I next load the scene. Does that seem like expected behaviour? Should a procedural mesh be able to live in a prefab?

avatar image KrishnaMV · Mar 04, 2013 at 11:31 AM 0
Share

can u explain me..hw u r creating that plane....?? ty

avatar image Statement · Mar 06, 2013 at 03:11 PM 0
Share

@$$anonymous$$rishna$$anonymous$$V: ?

@yoyo: Yeah, you need to create a new asset via AssetDatabase.CreateAsset - otherwise the mesh has no backing storage.

avatar image Statement · Mar 22, 2015 at 08:09 PM 0
Share

@yoyo The game object is one thing and the mesh is another thing. You have to "save both things" if you want a prefab with a mesh on it. Check out AssetDatabase.CreateAsset. If you dont save the mesh as well, it will be lost. This is expected behaviour. The only way a mesh could be saved without creating an asset would be for a game object in a scene to reference the mesh. If you then just save the scene, Unity will understand that the mesh belongs to the scene and serialise it into the scene itself. For prefabs you have to save the mesh yourself.

avatar image
2

Answer by Jesse Anders · Mar 07, 2011 at 05:52 PM

You can create one in a modeling program and import it. Or, you can write code (or use existing code) to create a 'quad' mesh procedurally.

I think there's a 'create plane mesh' script on the script wiki that allows you to specify the subdivision level, so you might look for that. If you get stuck though, post back (I have a script lying around somewhere that should do just what you're wanting).

[Drat...thwarted by a complete example! :)]

[@The OP: Note however that the above code will create a mesh procedurally at run time. If you just want a mesh model or quad prefab that can be shared between scenes/game objects, that can be done as well. (I have a 'quad' prefab that was generated this way that I use for sprites and that sort of thing.)]

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Statement · Mar 07, 2011 at 05:56 PM 1
Share

I do believe a neater solution would be to create a plane mesh model and import it into Unity from a modeling software though.

avatar image Jesse Anders · Mar 08, 2011 at 02:54 AM 0
Share

Sure, that works as well. The reason I did it procedurally was a) I couldn't figure out how to get Unity not to rotate/flip/re-arrange my Blender model on import (although that might have been user error), and b) I was already doing a lot of procedural mesh generation in the application, so writing a little code to generate some meshes that I needed was no big deal. But sure, one should use whatever method they find to be easiest and most straightforward.

avatar image dissidently · Mar 08, 2011 at 06:31 AM 0
Share

both of these are right answers. I feel bad for having to give the answer "tick" to Statement for his code. And even more so, because I'll probably go with the import a mesh plain option, which deserves a tick in and of itself.

avatar image
1

Answer by dentedpixel · Jan 19, 2012 at 05:30 PM

This script seems to be the most effective way to create a simple plane without having to bother with a 3d Editor:

[http://www.unifycommunity.com/wiki/index.php?title=CreatePlane][1] [1]: http://www.unifycommunity.com/wiki/index.php?title=CreatePlane

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NateJC · Jan 04, 2013 at 07:45 PM 0
Share

Best answer for me, thanks!

avatar image
0

Answer by Banglemoose · Mar 22, 2015 at 07:47 PM

Old thread but the Quad is 2 polygons for anyone who comes across this.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Detect perimetral walls of a room 1 Answer

Selecting a single polygon / face at runtime 1 Answer

Speedtree verts are insane 0 Answers

Vertex count 10 times higher in Unity 5 Answers

5 Player Models in Scene and already about 1.3 m Verts ? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges