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
0
Question by Ross_S · Jul 07, 2013 at 09:43 PM · gameobjectcolorinstancefadevertex

How to vertex colour a single instance of a GameObject?

My question is what is the best way to handle fading of individual instance of GameObjects?

It is my understanding that when I instantiate a new clone of a GameObject Prefab - the sharedMesh property of the MeshFilter of all the instances will point to the same mesh, meaning that if I vertex colour that mesh then they will all fade together (for example) instead of individually as I'd like.

If, on the other hand I used the meshFilter.mesh property then it does work but every frame, for each GameObject I'm creating a new mesh and these don't seem to be well cleaned up. I.e. the number of meshes in my scene on the profiler goes through the roof and on IOS devices the game starts to stutter from garbage collection.

I was previously using the material colour to fade them, but that had the same problem - i.e. loads of materials being created etc... (and breaks batching)

I do have a solution that works, I just have the feeling there must be a better way. So, in a script, not attached to the GameObject, but containing that gameObject - so responsible for Instantiating it etc... I create a mesh. When I instantiate a gameObject there I copy its sharedMesh and then store a pointer to my mesh in the .sharedMesh property of the MeshFilter. And then i perform the vertex colouring on the sharedMesh. So there is only ever one per Instantiated GameObject.

I should say that there are lots of these GameObject's appearing and being destroyed all the time. Kindof Particly...

so, any hints on where i'm being particularly dim here?

Thanks :)

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 robertbu · Jul 08, 2013 at 12:06 AM 0
Share

Have you tried forcing garbage collection at some frequency to smooth out the spikes?

 if (Time.frameCount % 30 == 0) {
     System.GC.Collect();
  }

http://docs.unity3d.com/Documentation/$$anonymous$$anual/UnderstandingAutomatic$$anonymous$$emory$$anonymous$$anagement.html

And you only changing the UVs of the existing mesh, not creating a whole new mesh each frame?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Jul 08, 2013 at 12:14 AM

When accessing the mesh property Unity will only create a copy of the shared mesh when this instance doesn't have it's own version yet. Once it's created the MeshFilter is decoupled from the sharedMesh and is using it's own instance from now on.

Unity won't create a new instance each time you access the mesh property.

Comment
Add comment · 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 Ross_S · Jul 08, 2013 at 07:24 AM 0
Share

Yes, sorry you're absolutely right and this in fact makes sense with the numbers... i.e. the mesh count is increasing by hundreds, not hundreds of thousands as it would be if a new mesh was being created each frame per object and not destroyed - duh.

So it seems that my problem then is that i'm instantiated these objects at a rate of about 1 per frame and that for each one when i access the mesh property it creates a single new mesh and when i call GameObject.Destroy(..) later on the object, that mesh is not being cleaned up. (I.e. the count continues going upwards in the profiler... ...and related to this is the stuttering on IOS because that all disappears when i use the solution that works as i outlined above...

avatar image Bunny83 · Jul 08, 2013 at 09:58 AM 0
Share

Right. I think it's pretty much the same with Renderer.material. Note the warning in the docs. I guess it's the same with the mesh property, so you have to destroy the mesh manually.

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

16 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

Related Questions

Transparency cube shader? 1 Answer

Why does camera not register color until objects are close up? 0 Answers

Fading a GameObject in/out 1 Answer

How Can i Fade In a GameObject with LeanTwean plugin? 1 Answer

iOS shader with no texture, just vertex colouring and main colour 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