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
2
Question by RaptorClaw · Feb 04, 2013 at 06:00 PM · meshcolor

setting vertex color of mesh not working

I'm trying to set the vertex color of a mesh. http://docs.unity3d.com/Documentation/ScriptReference/Mesh-colors.html

I have the following script attached to two objects in the scene. One of them is a custom mesh exported as FBX from 3DSMax and the other is a Unity Cube object.

     void Update () 
     {
         Mesh mesh = GetComponent<MeshFilter>().mesh;
         Vector3[] vertices = mesh.vertices;
         Color[] colors = new Color[vertices.Length];
         for (int i = 0; i < vertices.Length; i++)
         {
             colors[i] = Color.red;
         }
         mesh.colors = colors;
     }

What am I missing here? Why isn't the mesh changing color? Oh and I know that I could just change the material color I'm trying a more advanced effect I just paired down the code for this example.

Thanks guys

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

2 Replies

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

Answer by robertbu · Feb 04, 2013 at 06:04 PM

What you have should work. Are you sure your shader supports vertex color? What you are doing here is essentially what I did in the ChangeColor() method in this post, and it worked fine. There is a very simple vertex shader in this post as well.

http://answers.unity3d.com/questions/391561/create-a-mesh-and-color-cubes.html

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 RaptorClaw · Feb 04, 2013 at 06:16 PM 2
Share

AAAAWWWWWW of course I was using the default diffused shader. Thanks!!! If anyone else is interested here's a shader on the Wiki that supports multiple vertex colors: http://wiki.unity3d.com/index.php?title=VertexColor

avatar image Piesk · Oct 30, 2013 at 03:27 PM 0
Share

robert, I have the exact same problem, I attempting to change vert alpha's for use in a fog of war, in order to test it i set the visible area to yellow ins$$anonymous$$d of alpha = 0; absolutely nothing happened. I read your post and applied a vertex shader, still nothing happened. Is there any chance i could beg your assistance?

avatar image robertbu · Oct 30, 2013 at 03:35 PM 0
Share

In a new scene with some simple geometry, try your code with the shader at the link. If you cannot get it to work, post a new question along with your code.

avatar image
0

Answer by cockratice · Nov 30, 2016 at 07:38 AM

Hi I wonder if someone knows how to assign the new colors to the mesh as a slow transition over time, when using mesh.colors = colors the modification happens instantly but I am looking for if to happen as a slow transition. I've been trying using:

mesh.colors = Color.Lerp (colorsA, colorsB, t); or

But since colorsA and colorsB are arrays containing the different colors for each one of the mesh vertices I haven't managed to make Lerp work.

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 Bananozuar · Apr 29, 2017 at 11:45 PM 0
Share

you can lerp whole materials for that. Reffer to: https://docs.unity3d.com/ScriptReference/$$anonymous$$aterial.Lerp.html

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

12 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

Related Questions

Render voxels with RGB data passed to them 1 Answer

Changing Mesh Vertex Colors in editor 0 Answers

How would I change the color of a texture within an object with multiple textures? 1 Answer

Change color of mesh triangle based on Y position in world space 1 Answer

How to change the color of a mesh? 0 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