• 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 /
  • Help Room /
avatar image
Question by streeetwalker · May 03, 2018 at 05:01 PM · vertex colorvertexcolormesh color

Change a single vertex color after mesh is created?

for example, I've created a simple mesh with six vertices two triangles, and colored each vertex white at the start, and provided a vertex shader on the object that renders the mesh.

It works fine.

However, if I want to change the color of a triangle, say, defined by vertices with indexes 0, 1, and 2, at runtime after the mesh has been initially created and colored:

 myMesh.colors[0] = myNewColor;
 myMesh.colors[1] = myNewColor;
 myMesh.colors[2] = myNewColor;


(and myNewColor debugs to: RGBA(0.496, 0.647, 0.476, 0.000)

the new color doesn't stick - if I debug the vertices immediately after the obove statements, each vertex still has the old white color.

Is there something I am missing? No where to I see in the docs that mesh.colors is read only or anything... and I;m not getting any error codes...

Thanks for your help in advance

Comment

People who like this

0 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 streeetwalker · May 03, 2018 at 05:03 PM 0
Share

edit: if I debug myMesh.colors, the old color is there not the newly assigned color

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by streeetwalker · May 03, 2018 at 05:48 PM

I figured it out - mesh.color must immutable, though nowhere in the documentation does it state this. you have to make a copy of the array, modify the copy and then assign the copy to mesh.colors

Comment
Bunny83
Hellium

People who like this

0 Show 2 · 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 Bunny83 · May 03, 2018 at 10:34 PM 0
Share

All the vertex attributes are actually properties. So when reading them you actually create a copy of that array on the managed side which is filled with those attributes. The mesh is actually stored on the native C++ side so manipulating an array on the managed side of course won't magically send the changes to the native side and upload them to the GPU.


The Mesh documentation page actually mentions this, though a bit hidden:

Modifying vertex attributes every frame: a) get vertices b) modify them c) assign them back to the mesh.

avatar image streeetwalker Bunny83 · May 05, 2018 at 05:00 AM 0
Share

yeah, I caught that. That section of the documentation gives that as an example, but it doesn't explicitly state that it must be done that way to make it work. And yes, it must be done that way!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

138 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 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

Artifacts Shader Graph vertex colors 0 Answers

Heatmap Color Ramp on 3D model 1 Answer

TextMeshPro - Issues With Editing Vertex Values While Changing maxVisibleCharacters 0 Answers

Vertex coloring multiple submeshes different colors 0 Answers

Color a texture dynamically, best method? 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