Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by Sb_chit · Feb 12, 2018 at 02:29 PM · destroyuvuv mappinguvsuv2

Delete Uv2 of a mesh?

Hi all,

I have been creating secondary Uv during runtime. Now after creating it i would want to destroy the secondary Uv.

How do you delete the secondary UV in runtime ? I Hope, I’m clear enough to make my question undestandable. Thanks in advance.

Comment
Add comment
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

1 Reply

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

Answer by AlucardJay · Apr 10, 2018 at 09:23 AM

Disclaimer: I've never played with the uv2 channel, so these are the rantings of a madman.

I see 2 options :

1/ Assign the uv2 as null

2/ Create a copy of the mesh, but without assigning any uv2

example script :

In a new project, new scene, create an empty gameObject. Attach the following script, and add a material with a texture to see what's happening.

In play mode : press G to generate mesh with UVs; press R to null the UVs; press U to make a copy without UVs.

 using UnityEngine;
 using System.Collections;
 
 
 [RequireComponent( typeof(MeshFilter), typeof(MeshRenderer) )]
 public class MeshRemoveUV : MonoBehaviour 
 {
     
     //    -------------------------------------------------------  Persistent Functions
     
     
     void Start() 
     {
         GetComponent< MeshFilter >().mesh = GenerateMesh();
     }
     
     
     void Update() 
     {
         if ( Input.GetKeyDown( KeyCode.G ) )
         {
             GetComponent< MeshFilter >().mesh = GenerateMesh();
             return;
         }
 
         if ( Input.GetKeyDown( KeyCode.R ) )
         {
             GetComponent< MeshFilter >().mesh = NullifyUV( GetComponent< MeshFilter >().mesh );
             return;
         }
 
         if ( Input.GetKeyDown( KeyCode.U ) )
         {
             GetComponent< MeshFilter >().mesh = CopyMeshWithoutUV( GetComponent< MeshFilter >().mesh );
         }
     }
     
     
     //    -------------------------------------------------------  Other Functions
     
     
     Mesh NullifyUV( Mesh mesh ) 
     {
         mesh.name = "NullUVs";
         mesh.uv = null;
 
         return mesh;
     }
     
     
     Mesh CopyMeshWithoutUV( Mesh meshWithUVs ) 
     {
         Mesh mesh = new Mesh();
 
         Vector3[] verts = new Vector3[ meshWithUVs.vertices.Length ];
         System.Array.Copy( meshWithUVs.vertices, verts, meshWithUVs.vertices.Length );
 
         int[] tris = new int[ meshWithUVs.triangles.Length ];
         System.Array.Copy( meshWithUVs.triangles, tris, meshWithUVs.triangles.Length );
 
         Vector3[] norms = new Vector3[ meshWithUVs.normals.Length ];
         System.Array.Copy( meshWithUVs.normals, norms, meshWithUVs.normals.Length );
 
         mesh.name = "WithoutUVs";
         mesh.vertices = verts;
         mesh.triangles = tris;
         mesh.normals = norms;
 
         mesh.RecalculateBounds();
 
         return mesh;
     }
     
     
     Mesh GenerateMesh() 
     {
         Mesh mesh = new Mesh();
 
         Vector3[] verts = new Vector3[ 4 ];
         verts[ 0 ] = new Vector3( 0, 1, 0 );
         verts[ 1 ] = new Vector3( 1, 1, 0 );
         verts[ 2 ] = new Vector3( 0, 0, 0 );
         verts[ 3 ] = new Vector3( 1, 0, 0 );
 
         Vector3[] norms = new Vector3[ 4 ];
         norms[ 0 ] = -Vector3.forward;
         norms[ 1 ] = -Vector3.forward;
         norms[ 2 ] = -Vector3.forward;
         norms[ 3 ] = -Vector3.forward;
 
         int[] tris = new int[ 6 ];
         tris[ 0 ] = 0;
         tris[ 1 ] = 1;
         tris[ 2 ] = 2;
         tris[ 3 ] = 2;
         tris[ 4 ] = 1;
         tris[ 5 ] = 3;
 
         Vector2[] uvs = new Vector2[ 4 ];
         uvs[ 0 ] = new Vector2( 0, 1 );
         uvs[ 1 ] = new Vector2( 1, 1 );
         uvs[ 2 ] = new Vector2( 0, 0 );
         uvs[ 3 ] = new Vector2( 1, 0 );
 
         mesh.name = "HasUVs";
         mesh.vertices = verts;
         mesh.triangles = tris;
         mesh.normals = norms;
         mesh.uv = uvs;
 
         mesh.RecalculateBounds();
 
         return mesh;
     }
 }
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 Sb_chit · Apr 13, 2018 at 06:23 AM 0
Share

Hey thank you for the reply, the option 2 mentioned above works well. But there is another issue now, once after generating the new mesh , and then i try to create a prefab of the gameobject. It shows the mesh is missing.

How do you create a prefab from the newly generated mesh ? I Hope, I’m clear enough to make my question undestandable. Thanks in advance.

avatar image AlucardJay Sb_chit · Apr 13, 2018 at 01:41 PM 0
Share

Do you want to : 1/ use the mesh only in the same play session; or 2/ use the mesh after the game has been closed, and then restarted?

avatar image Sb_chit AlucardJay · Apr 17, 2018 at 05:26 AM 0
Share

Option 2. I need to use the mesh after the game has been closed and then restarted.

Thanks in advance.

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

79 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Normalizing mesh UVS? 1 Answer

Procedural Mesh UV Problem (UVs 'mirrored' instead of 'repeating') 0 Answers

Procedural Mesh UV problem 0 Answers

Creating a mesh programatically for a tile-based 2D game 1 Answer

Sprite animation on quad with UV-coordinates 1 Answer


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