• 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 Bunnybomb7670 · Jul 29, 2016 at 10:12 PM · meshrenderingprocedural mesh

Vertex Colours flickering blue

Hi,

I am working on a little custom trail script for my game and I've ran into an issue. Basically when there is one in the scene it works fine, the vertex colour is set, but as soon as I create a second instance it will change both meshes to blue and occasionally flicker back to the original colour.

The shader I am currently using is the Shaders/Mobile/Particles/Alpha Blended w$$anonymous$$ch I assume uses vertex colouring somewhere as the colours do change, however I am not sure how to approach the issue I'm running into.

I read around a little online and I believe that it is related to Dynamic batc$$anonymous$$ng but I am not sure if t$$anonymous$$s is true, if so, is there a way to get around the issue?

[EDIT] I disabled Dynamic batc$$anonymous$$ng and it fixed the issue, however that means none of my game can benefit from Dynamic batc$$anonymous$$ng, is there a way to flag these as non-batchable?

alt text

And here is the code w$$anonymous$$ch is used to generate t$$anonymous$$s trail effect so far :

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 
 using UnityEngine;
 
 namespace PlanetDefender
 {
     [RequireComponent(typeof(MeshRenderer), typeof(MeshFilter))]
     public class Trail : MonoBehaviour
     {
         private Vector3[] _vertices;
         private int[] _indices;
         private Color[] _colours;
         private Mesh _mesh;
 
         [SerializeField]
         private float _startWidth;
         [SerializeField]
         private float _endWidth;
         [SerializeField]
         private float _length;
         [SerializeField]
         private Color _startColour;
         [SerializeField]
         private Color _endColour;
 
         public float startWidth
         {
             get { return _startWidth; }
             set
             {
                 _startWidth = value;
                 rebuild();
             }
         }
 
         public float endWidth
         {
             get { return _endWidth; }
             set
             {
                 _endWidth = value;
                 rebuild();
             }
         }
 
         public float length
         {
             get { return _length; }
             set
             {
                 _length = value;
                 rebuild();
             }
         }
 
         public Color startColour
         {
             get { return _startColour; }
             set
             {
                 _startColour = value;
                 rebuild();
             }
         }
 
         public Color endColour
         {
             get { return _endColour; }
             set
             {
                 _endColour = value;
                 rebuild();
             }
         }
 
         private MeshFilter _meshFilter;
 
         void Awake()
         {
             _meshFilter = GetComponent<MeshFilter>();
             _mesh = new Mesh();
             _meshFilter.sharedMesh = _mesh;
 
             _indices = new int[] { 0, 2, 1, 2, 0, 3 };
             _vertices = new Vector3[4];
             _colours = new Color[4];
 
             rebuild();
         }
 
         // Catch an editor value change
         void OnValidate()
         {
             // Prevent editor running code unless its ingame
             if (_vertices != null && _vertices.Length > 0)
             {
               //  rebuild();
             }
         }
 
         private void rebuild()
         {
             _vertices[0] = new Vector3(-_endWidth, _length, 0);
             _vertices[1] = new Vector3(-_startWidth, 0, 0);
             _vertices[2] = new Vector3(_startWidth, 0, 0);
             _vertices[3] = new Vector3(_endWidth, _length, 0);
 
             _colours[0] = _endColour;
             _colours[1] = _startColour;
             _colours[2] = _startColour;
             _colours[3] = _endColour;
 
             _mesh.vertices = _vertices;
             _mesh.colors = _colours;
             _mesh.SetIndices(_indices, MeshTopology.Triangles, 0);
 
             _mesh.RecalculateNormals();
             _mesh.RecalculateBounds();
             _mesh.Optimize();
         }
     }
 }



issue.png (33.6 kB)
Comment

People who like this

0 Show 0
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

0 Replies

· Add your reply
  • Sort: 

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

56 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

Related Questions

Shadow artifects on mesh with Standard shader 1 Answer

Procedurally Generated mesh not rendering all triangles,Procedurally generated mesh isn't rendering all triangles? 1 Answer

Re-use lightmap for different mesh with same lightmap uvs 0 Answers

Simple plane generation 1 Answer

Weird bounce on collision with perfectly aligned (generated) meshes for fast object 3 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