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
1
Question by zettam · Nov 18, 2013 at 12:44 AM · particlesspawnshuriken

Spawn particles from a position

Is it possible to spawn particles from defined positions within a shuriken particle system?

I want to spawn the particles, and let them use the existing settings of the particle ystem such as start lifetime, size, force with all random values and details; just like a randomly spawned particle in that particle system

Any ideas?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by mptp · Oct 09, 2014 at 02:02 PM

This is an old question, but thought I'd answer here for posterity:

What you want to do is have a particle system, and each frame add some new particles that you create through code to its list of particles. I put a complete demo here which should be pretty clear.

 ParticleSystem yourParts = GameObject.Find("yourParts").GetComponent<ParticleSystem>();
 int partsPerFrame = 20;
 
 void Update() {
   //Get the particles already in the system
   ParticleSystem.Particle[] particles_original = new ParticleSystem.Particle[yourParts.particleCount];
   yourParts.GetParticles (particles_original);
 
   //Make an array of particles to add
   ParticleSystem.Particle[] particles_new = new ParticleSystem.Particle[partsPerFrame];
   Vector3 spawnPos;
   for(int i = 0; i < partsPerFrame; i++) {
     //Here I'm setting their position randomly, but you could pass any position you want here
     spawnPos = new Vector3(Random.Range(-10.0f, 10.0f), Random.Range(-10.0f, 10.0f), Random.Range(-10.0f, 10.0f));
     particles_new[i] = makePart(spawnPos);
   }
 
   //Combine the currently existing particles with the new ones you just created
   ParticleSystem.Particle[] particles_final = new ParticleSystem.Particle[particles_original.Length + particles_new.Length];
   particles_original.CopyTo(particles_final, 0);
   particles_new.CopyTo(particles_final, particles_original.Length);
 
   //And put them into the particle system
   yourParts.SetParticles (particles_final, particles_final.Length);
 }
 
 //This initialises all of the ParticleSystem.Particle attributes whenever you make one.
 //Each attribute is assigned a variable that I store as class variables. I didn't write them in because it would end up too messy looking.
 ParticleSystem.Particle makePart(Vector3 position) {
         ParticleSystem.Particle r = new ParticleSystem.Particle();
         r.angularVelocity = part_angularVelocity;
         r.color = part_color;
         r.lifetime = part_lifetime;
         r.position = position;
         r.rotation = part_rotation;
         r.size = part_size;
         r.startLifetime = part_startLifetime;
         r.velocity = part_velocity;
         
         return r;
     }
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
1

Answer by petersvp · Nov 08, 2015 at 02:47 AM

@zettam, There is another, more efficient and very easy way:

Make your particle system simulate in World Space, and make special object that only holds your particle system.

Then, every time you want to burst, just move the emitter into the position you want, and burst there.

If you want to burst in two or more places at the same time, make array / list op positions, and in the update() on your script, teleport-emit() in all these positions.

Just don't forget to set the system to simulate in World space, because in local space, particles will be parented to the object :)

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
0

Answer by Cherno · Nov 18, 2013 at 01:20 AM

Wouldn't this just mean that you instantiate a prefab particle system at the required location that has the required values, but just one single particle?

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
0

Answer by cobertos · May 08, 2020 at 02:02 AM

You can use ParticleSystem.Emit() and provide overrides for the .position property

https://docs.unity3d.com/ScriptReference/ParticleSystem.Emit.html

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

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

22 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

Related Questions

Shuriken Collision Detection 0 Answers

Adjust particles to simluate real world 0 Answers

Shuriken Particle Collisions - Collider shape? 0 Answers

Get all particles within trigger collider? 1 Answer

How do I Update the transform of Instantiate prefab? 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