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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Damocles · Oct 08, 2012 at 08:50 PM · particlesshuriken

[Shuriken] emitting particles at arbitrary locations

I have a particle system, which I want to emit at a series of randomly determined points all during the same frame. Through testing, I find that I can simply set pfx.transform.position to the location and the particles will emit there when I call pfx.Emit(n).

However, When trying to make several particles at once in different locations, looping through several times and changing the pfx position before a call to pfx.Emit(1) does not work - they all emit in the first location set. Weird.

Here's the code I'm using:

             // go is a game object var from earlier
         Mesh m = go.GetComponent<MeshFilter>().mesh;
 
         int cnt = m.vertices.Length;
         int numParts = 10;
 
         for (int i = 0; i < numParts; ++i)
         {
             Vector3 vpos = m.vertices[(int)(math.FRand() * cnt)];
                     // p is a ParticleSystem object
             p.transform.position = go.transform.TransformPoint(vpos);
 
             Debug.Log("vpos " + vpos + " tranforms into " + go.transform.TransformPoint(vpos));
             
             p.Emit(1);
         }

The debug I have in there shows me that the transformed positions are all correct, but only the first call to p.transform.position = go.transform.TransformPoint(vpos) seems to have any effect. I think this is perhaps something to do with needing to update a frame first? I've used similar code before to make trails on moving objects, but they emit in one place per frame, not several places at once.

Has anyone experienced this or know a way around it?

Comment
Add comment · Show 2
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 ThePunisher · Oct 08, 2012 at 10:38 PM 0
Share

Let me see if I understand you correctly. You want to use the same particle system to emit particles at different positions within the same frame? Not sure if that's possible.

Have you tried changing the position within consecutive frames? Don't think the player would be able to see the difference.

avatar image Damocles · Oct 09, 2012 at 06:31 AM 0
Share

Consecutive frames works fine, just not the same frame. It's very strange that the first call to set the position of the emitter works, but subsequent calls don't seem to move it until the next frame.

Although thinking about it, it's probably the last position call that 'works'. I guess Unity doesn't update new positions until the internal frame logic fires. What a nuisance.

1 Reply

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

Answer by foxor · Nov 13, 2012 at 07:59 PM

That sounds like a bug with Emit to me. Here's how you can work around it:

 p.Emit(numParts)
 ParticleSystem.Particle[] particles = new ParticleSystem.Particle[numParts];
 if (particleSystem.GetParticles(particles) < numParts) {
   Debug.Log("Hey!");
   return;
 }
 for (int i = 0; i < numCount; i++) {
   particles[i].position = ...
 }

It doesn't work if you're using that emitter for other things, but it should work around your problem.

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 Damocles · Nov 13, 2012 at 08:10 PM 0
Share

Thanks foxor but you're a touch too late - they have just fixed it in Unity4. You can now emit in specific locations, or by passing in an array of Particles. Have a tick anyway - it's still useful for v3 users.

avatar image foxor · Nov 13, 2012 at 08:13 PM 0
Share

Yeah, I was looking for a different problem in unity4, but I figured I could at least answer this one.

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

11 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

Related Questions

Particle System(Shuriken) optimization problem 1 Answer

Setting the position of particles in a (shuriken) ParticleSystem 3 Answers

Scale Shuriken Particle System with Parent Transform 5 Answers

How to pause emitter in new Particle System? 2 Answers

Particles - start speed curve doesn't work? 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