• 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
Question by DedRed · Mar 27, 2017 at 03:55 PM · vertex color

How to get vertex color before assigning color via Mesh.colors?

I have a mesh that has vertex colors already painted in (from Maya). I can confirm they are there using a shader to see vertex color. Is there a way to sample those vertex colors from a script using the Mesh.colors api? It seems like that array of colors is empty until I assign it a new array of colors.

Same question worded another way: I want to get the vertex colors of a mesh via script, as the mesh currently is. I don't want to assign a new array of colors (which would override the current vertex colors) in order to sample them. Is there a way to do this?

Comment
Jagrafess

People who like this

1 Show 2
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 Jagrafess · Mar 19, 2020 at 10:36 AM 0
Share

I am also having this issue but only for builds (debug works fine), the colours work when the mesh is put directly into the scene but if I instanciate it in real-time the colour data seems to be empty. I'm using Unity 2020.1.0b2, but I've had this issue in earlier versions. I get around it by manually placing all my meshes in the scene with a material that uses vertex colours then I delete them. However this seems like really ugly hack especially as I build more and more models.

avatar image Bunny83 Jagrafess · Mar 19, 2020 at 11:12 AM 0
Share

That doesn't make much sense. If you place an object in the scene or instantiate it at runtime you do not instantiate the mesh referenced by the MeshFilter / SkinnedMeshRenderer. The actual Mesh asset does not get duplicated at all unless you manually duplicate it (which wouldn't make much sense).


Keep in mind that manipulating or reading the "mesh" property of a MeshFilter would automatically duplicate the mesh for this meshfilter only. Such auto instantiatings have to be destroyed manually.


I doubt that your "solution" would actually fix that issue. It's more likely that the mesh hasn't been imported as readable. If a mesh or texture isn't marked as readable then it's data is just loaded in the beginning, directly uploaded to the GPU and from that point on no longer available to the scripting environment. By marking a texture or mesh read / writeable Unity will essentially hold a copy in RAM. So you really should be careful about what assets you mark as readable.


Finally do not do general tests in alpha or beta versions or if you don't post any errors or bugs here in UnityAnswers. If you are a beta tester please read the beta tester guide. Actual verifed bugs should be reported through Unity's bug reporter tool from inside Unity. Anything else related to alpha / beta versions should belong to the beta forum

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by Bunny83 · Mar 19, 2020 at 10:58 AM

If the mesh is imported in Unity, make sure you mark it as readable in the inspector. You can check if a mesh is readable with the isReadable property.

Comment

People who like this

0 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 Jagrafess · Mar 19, 2020 at 11:01 AM 0
Share

That's just the "Read/Write Enabled" option on the imported mesh right? I've got that on and I can manipulate the mesh, it's just that the color information is emptied out (only in builds)

I've added another question explaining it in better detail here: https://answers.unity.com/questions/1709168/vertex-color-emptied-after-instanciating-mesh-at-r.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.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

(noob) Vertex Color from 3dsmax 0 Answers

Mesh.colors doesn't work even though colors are passed correctly to the array 1 Answer

In which format does Unity read vertex colors from .obj files? 1 Answer

Vertex colors are being stripped after build 1 Answer

Best practice to change vertex color on a large amount of quads? 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