Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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 Paulius-Liekis · Jun 30, 2013 at 08:07 AM · inspectorparticlesystemreflectionapi

How to modify ParticleSystem from Editor script?

Exposed ParticleSystem API is very limitted (http://docs.unity3d.com/Documentation/ScriptReference/ParticleSystem.html). For example you can not access "Size over lifetime" or "Rotation over lifetime" or simply set lifetime as "random between two constants" from script.

Has anyone found a way to do that? Through reflection? Through some hack using the inspector script?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Paulius-Liekis · Jun 30, 2013 at 09:19 PM

It looks like it's possible, it's just not very straight forward. You can modify private variables using this trick:

 var so : SerializedObject = new SerializedObject(Selection.activeGameObject.GetComponent(Renderer));
 so.FindProperty("m_ScaleInLightmap").floatValue = 0.9;
 so.ApplyModifiedProperties();

You can iterate all serializable properties using this loop:

 SerializedObject so = new SerializedObject(particleSystem);
 SerializedProperty it = so.GetIterator();
 while (it.Next(true))
     Debug.Log (it.propertyPath);

After that you will notice that ParticleSystem has a bunch of properties like InitialModule, SizeModule, etc. Each sub-property like InitialModule.startLifetime has a property minMaxState (int value from 0 to 3) representing 4 states:

  1. Constant

  2. Curve

  3. Random between two constants

  4. Random between two curves

There are three properties to store these values: scalar, minCurve, maxCurve. Note that minCurve/maxCurve.keys[0].value is used for storing extra data for "Random between two constants".

Comment
Add comment · Show 3 · 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 Idioismist · Jun 20, 2014 at 05:07 PM 2
Share

Warning, as of Unity4.5, the accepted answer to this question will not work for most people. SerializedObject is in the UnityEditor namespace and, therefore, IS NOT AVAILABLE at run-time. Attempting to build a project that references the UnityEditor namespace will result in failure.

If your intention is to access a ParticleSystem during run-time to dynamically change effects, unfortunately, you still only have access to those handful of properties publicly exposed by the ParticleSystem component.

Hopefully this will change in Unity5, but this has been a persistent limitation since Unity3. Those of us who rely more heavily on scripting than on the editor still have to use the legacy particle system to gain more--though still not total--control of our particle systems.

avatar image Paulius-Liekis · Jun 20, 2014 at 08:21 PM 0
Share

In my case the intention was for Editor only, e.g. importing full particle setup from 3ds$$anonymous$$ax.

avatar image noio · Aug 07, 2014 at 01:11 PM 0
Share

This is kind of messed up. :|

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

17 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

Related Questions

Building a Collection of Subclasses and Modifying Their Public Members from the Inspector 0 Answers

How does Unity sort fields in order of their declaration? 1 Answer

Make popup window in inspector if deleting GameObject 0 Answers

How can I hide a MonoBehaviour from the Inspector? (or make it extremely thin or compact) 1 Answer

Custom Editor: Inspect members of GameObject 2 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