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
8
Question by azykise · Jan 14, 2013 at 10:45 AM · shuriken

how to access Shuriken Particle System Modules in script

hi guys, i want to access the new particle system modules such as "emission" and "shape" in script, so that i can change the particle style during runtime . but i can not find any api to access the modules after i get the ParticleSystem component. is there a way to access the modules using script ? how ? thanks a lot !

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 MattewMarkson · Jan 14, 2013 at 11:23 AM 0
Share

you need to use ellipsoid particle

6 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by flyingbanana · Apr 17, 2015 at 11:34 PM

You can't by normal means, however, with the aid of legacy animations, you can.

First, add the Animation component (not Animator!) to your object you want to animate.

Then in code, each time you want to animate a property, use this snippet:

 Animation animation = GetComponent<Animation>();
 AnimationCurve curve = AnimationCurve.Linear(startTime, startValue, endTime, endValue);
 AnimationClip clip = new AnimationClip();
 clip.legacy = true;
 clip.SetCurve("", typeof(ParticleSystem), "ShapeModule.radius", curve);
 animation.AddClip(clip, "Resize");
 animation.Play("Resize");

The above code will animate the radius property of the shape module from start value to end value. In general, the property key is named "nameModule.property", but if you want to know for sure, do the following:

  1. Under Edit > Project Settings > Editor, change Asset Serialization mode to Force Text

  2. Look for the scene containing your particle effect. Open in text editor.

  3. Search for the particle system and look for the key you want to change.

Of course, for an instantaneous change, just define the animation curve to be something like

 AnimationCurve curve = AnimationCurve.Linear(0, 0, 0, newValue);

Took me a while to get it working! :)

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

Answer by Bocharick · Feb 10, 2016 at 09:00 PM

I found solution of changing shape through script.

NOT working:

 public ParticleSystem psystem;
 void Start(){
 psystem.shape.box = new Vector3(2,2,2); // error, couldn't compile
 //psystem.shape.box.Set(2,2,2); // has no error, and compile, but has no results
 }

Working:

     public ParticleSystem psystem;
     void Start(){
     var x = psystem.shape;
     x.box = new Vector3(2,2,2); // solve my problem
     //x.box.Set(2,2,2); - still has no error, but still has no results
     // if you want change shape cone radius - x.radius = 34345;
     }

Hope it will helpfull

Comment
Add comment · Show 6 · 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 meat5000 ♦ · Feb 10, 2016 at 09:15 PM 0
Share

Your Not Working snippet didnt work because you didnt use GetComponent on the Particle System, I reckon.

avatar image Bocharick meat5000 ♦ · Feb 11, 2016 at 04:42 AM 0
Share

show me your "Getcomponent" variant plz, cause i don't understand it.

avatar image meat5000 ♦ Bocharick · Feb 11, 2016 at 07:16 AM 0
Share

Basically, when you define your variable

  public ParticleSystem psystem;

its an empty instance (usually).

 void Start(){
       psystem = GetComponent<ParticleSystem>();

The GetComponent retrieves the object's instance and now your system is a reference to it..

Show more comments
avatar image Vacummus · Feb 23, 2016 at 11:56 PM 0
Share

This works and is the best solution yet. Thanks for sharing!

avatar image
0

Answer by WILEz1975 · Sep 05, 2014 at 02:10 PM

You can modify all variables.

For example, i change my angle shape:

 SerializedObject so = new SerializedObject(GetComponent<ParticleSystem>());
 so.FindProperty("ShapeModule.angle").floatValue = 25f;
 so.ApplyModifiedProperties();

You can see all particleSystem propriety with:

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

(sorry for my bad english, i'm italian).

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 Pendrokar · Oct 16, 2014 at 06:54 PM 1
Share

"SerializedObject" only seems available only with UnityEditor namespace, but even when I add that, the Apply$$anonymous$$odifiedProperties does not affect the component. So I don't think this solution works for OP too:

so that i can change the particle style during runtime

avatar image omerfarukz · Apr 14, 2015 at 09:06 PM 0
Share

it's works in only an editor.

avatar image
0

Answer by CodeMasterMike · Jan 14, 2013 at 11:36 AM

Read the documentation on what variables and functions you can access with the Shuriken particle system, because you can't change "shape" through scripts. You can only change those in the editor.

Shuriken particle system documentation

Good luck!

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 rosevelt · May 07, 2013 at 05:49 PM 4
Share

Sorry for being that bold, but not having full access to shurikan modules from code is like half baked cake.

imagine that a project has hundreds of prefabs which all needs a mesh based particles, the only way of having it now is by duplicating. now, if it need some tuning, it's a pain and not fun going on all duplications again.

This must be added ASAP.

avatar image ExTheSea · May 07, 2013 at 05:50 PM 0
Share

I converted your answer to a comment because the answer are really just used to answer the main question.

avatar image
0

Answer by rawrrrz · Feb 29, 2016 at 12:07 PM

Old question, but I just came across this trying to google for myself. To explain what I was doing a bit, in a 'diablo-ish' kind of game, I have a spell explode, and attach an 'I'm on fire!!' effect object.. By default, it's just a lame little sphere as it's default emission shape, so depending on what it hit I then wanted to change it from emitting my sphere to SkinnedMeshRenderer, MeshRenderer, etc..

Firstly, I declared a GameObject parentObject; and set it with my OnCollision script, as my meshes are always buried in child objects of the monster's parent containing my collider.

 //Get particleSystem's ShapeModule
 ParticleSystem particleSystem = GetComponent<ParticleSystem>();
 ParticleSystem.ShapeModule shapeModule = particleSystem.shape;

 //Check&Set for MeshRenderer, set Shape MODULE's ParticleSystemShapeType
 if (parentObject.GetComponentInChildren<SkinnedMeshRenderer>())
 {
     shapeModule.shapeType = ParticleSystemShapeType.SkinnedMeshRenderer;
     shapeModule.skinnedMeshRenderer = parentObject.GetComponentInChildren<SkinnedMeshRenderer>();
 }

Just a snippet, I change more variables, like meshShapeType (Vert/Edge/Tri), which I actually found before just shapeType, but it gave me hope! lol, and useMeshColors, etc.., and else if through the other types, then if none found, it'll just stay it'll silly default sphere emitter.. and it works like a charm in my project's latest build!

Really took some digging to find "shapeType". I kept trying to change .shape assuming it was the Shape Property and not the Shape Module.. Finally IntelliSense said 'MODULE', and I recalled the docs.. http://docs.unity3d.com/Manual/ParticleSystemModules.html .. So, that's why I purposely declared particleSystem and shapeModule in that way, to illustrate what about this made me feel the most stupid and caused me to google lol! :D

Also may need to note that I'm on 5.3.2p2.. I'm a few patches behind now, but they've been working a lot on the Particle System recently, so this may still be fairly new.. Anyways, hope this helps someone access their variables, in case I wasn't the last person still trying. :)

Comment
Add comment · 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
  • 1
  • 2
  • ›

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

19 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

Related Questions

Set a range of startSpeed for Shuriken via script 2 Answers

Shuriken Scripting, disappointed 1 Answer

Change new Shuriken Particle System mesh/texture in script? 0 Answers

shuriken auto destruct script doesn't ALWAYS work? 2 Answers

Have null errors 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