Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 stealann · Nov 13, 2012 at 05:04 PM · particlesystemparticleanimator

How to change particle system's "color over lifetime" by script?

Simply description of my question:

I have a particle(attached a particle system to an empty game object) and I already set the "Color over Lifetime" attribute in inspector. Now I want to reset the "Color over lifetime" to another pattern after an event is triggered.

the problem is that: I can't find any variables and functions could be used directly finish the job. Is there any?

I tried to attach ParticleAnimator to the same gameObject but it doesn't work. Is there any good way to solve the problem? Or should I get all the particles emitted by the system and adjust them one by one in my script?

The pic below shows how i set the ParticleSystem and ParticleAnimator. But the particle remains green and yellow. Did I do something wrong? Help!!! Thank you very much.

[1]: /storage/temp/4918-particleproblem.png

particleproblem.png (70.0 kB)
Comment
Add comment · Show 3
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 Scribe · Nov 13, 2012 at 07:04 PM 0
Share

http://docs.unity3d.com/Documentation/ScriptReference/ParticleAnimator-colorAnimation.html - As it says, you can't modify one element of the array currently, you have to set the whole array and then assign it, but that shouldn't be too bad.

Scribe

avatar image stealann · Nov 14, 2012 at 04:04 AM 0
Share

@Scribe Thank you for your reply. But sorry it didn't solve my problem. I did read the scripting reference of ParticleAnimator. Actually I want to find some way to solve the problem without ParticleAnimator if there is. Since the particle system has the "Color over Lifetime" item, then Why can't I script directly with Particle System interface?

And I haven't tried scripting the Animator yet. Just edited it in inspector as you can see from my pic but the color of my particle didn't change. Does Animator only works by scripting? Then what does the items in inspector do?

avatar image stealann · Nov 14, 2012 at 05:59 AM 0
Share

@Scribe I just noticed that Particle system and particle Animator seems to be parallel components. I think that's why the animator component I added doesn't work for the particle system. But in docs for the old version of Unity, it saids Particle system is composed of emitter, animator and renderer. But in the latest version of unity the inspcetor interface of particle system changed and when I tried to get the animator component in object attached with Particle system, it returns NULL. Does this mean I can't change the color over life time of particles emitted by particle system with animator component?

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by zhuk1011 · Jan 28, 2016 at 01:28 PM

http://docs.unity3d.com/ScriptReference/ParticleSystem-colorOverLifetime.html

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 Kimi073 · Feb 02, 2016 at 05:03 PM 0
Share

I'm so sorry to say but, this seems does not work for me

I have tried the example code but it gives 2 errors:

colorOverLifeTime is not a definition in ParticleSystem

$$anonymous$$in$$anonymous$$axGradient does not exit

avatar image JPhilipp · Aug 16, 2016 at 10:43 AM 0
Share

FWIW it works here, thanks!

avatar image
1

Answer by CodeMasterMike · Nov 14, 2012 at 06:43 AM

Just using script it seems that you cant set the "color over lifetime" color, either for each individual particle, or for the whole particle system.

However, you can set the color for each individual particle, and use your own "color over lifetime" Lerp calculation.

         ParticleSystem m_currentParticleEffect = (ParticleSystem)GetComponent("ParticleSystem");
         ParticleSystem.Particle []ParticleList = new    ParticleSystem.Particle[m_currentParticleEffect.particleCount];
         m_currentParticleEffect.GetParticles(ParticleList);
         for(int i = 0; i < ParticleList.Length; ++i)
         {
             float LifeProcentage = (ParticleList[i].lifetime / ParticleList[i].startLifetime);
             ParticleList[i].color = Color.Lerp(Color.clear, Color.red, LifeProcentage);
         }   
         
         m_currentParticleEffect.SetParticles(ParticleList, m_currentParticleEffect.particleCount);


This is probably very expensive if the effect as lots of particles, so its maybe not a suitable sollution for all systems.

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 stealann · Nov 14, 2012 at 07:19 AM 0
Share

This is exactly what I want! Thank you! I think particle system should have the color over lifetime be its interface, which make things a little easier, and maybe better performance?

avatar image CodeMasterMike · Nov 14, 2012 at 09:32 AM 0
Share

$$anonymous$$aybe they will add more functionality to the particle system through scripting in later Unity versions?

All variables, including color over lifetime, must be stored somewhere. But simply isn't reachable from a script.

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

14 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

Related Questions

NoobQuestion: Help With Particles - Simple 2 Answers

ParticleSystem interpolates position when moved and off 1 Answer

Particle Sytem with Prefabs 0 Answers

Particle System Attached to Prefab 1 Answer

Reset a ParticleSystem with chidren 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