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
0
Question by $$anonymous$$ · Aug 05, 2013 at 12:58 PM · c#particlesmovelegacy

How to move particles from script ?

Im trying to move all particles to a spot. I wrote a script,but it doesnt work.

 for(int i  = 0; i < particleEmitter.particles.Length;i++)
         {
         particleEmitter.particles[i].position = Vector3.MoveTowards(particleEmitter.particles[i].position,spot.transform.position,Time.deltaTime * speed);
         }
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

3 Replies

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

Answer by CHPedersen · Aug 05, 2013 at 01:05 PM

It's because your script isn't reassigning the particle array back to the emitter. Notice that ParticleEmitter.particles is a property, not a public variable. This indicates it's implemented as a set of getter/setter methods. The get method, which is called when you access the property, actually returns a deep-copy of the actual array. This behavior is similar to how eg. the vertices array of the Mesh class works. You can then make changes to this copy as you see fit, but they will not take effect until you assign the copy back to the emitter:

     // Extract copy
     Particle[] particles = particleEmitter.particles;

     // Do changes
     for (int i = 0; i < particles.Length; i++)
     {
         particles[i].position = Vector3.MoveTowards(particleEmitter.particles[i].position, spot.transform.position, Time.deltaTime * speed);
     }

     // Reassign back to emitter
     particleEmitter.particles = particles;

Beware, for the record, that modifying particles in this manner can be very inefficient when there are thousands of particles. Be especially careful about calling list properties in loop conditions the way you did in your original code. Since the property returns a full copy of the entire particle array every time you call particleEmitter.particles, it means you're assigning a new array of all particles every time the loop iterates, because it accesses the particles-property to check the length on every iteration. This would create a massive memory overhead. I've circumvented that by storing the copy once outside the loop (at the line commented "Extract copy").

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 $$anonymous$$ · Aug 05, 2013 at 01:09 PM 0
Share

Thank you :D

avatar image $$anonymous$$ · Aug 05, 2013 at 03:02 PM 0
Share

How can i do this without massive memory overhead?

avatar image
0

Answer by ryisnelly · Aug 05, 2013 at 01:01 PM

cant you use unitys built in particle system? Components>Effects>Particle System

Comment
Add comment · Show 1 · 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 RealSoftGames · Apr 14, 2017 at 03:49 AM 0
Share

thats what he is doing, however it does not have the needed functionality to get the expected behaviour

i myself need to code in patterns for each particle and this is pretty much the only way to do it that i have found.

avatar image
0

Answer by mavin_197 · Oct 18, 2018 at 11:20 AM

And you need to SetParticles

int count = this.particleSys.GetParticles(this.particles); this.particleSys.SetParticles(this.particles, count);

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

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

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Still trying to move walls 1 Answer

How to move an object in world with script 1 Answer

Create Legacy Ellipsoid Emitter from script 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