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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
5
Question by Robert-Castle · Jun 01, 2012 at 10:47 AM · positionparticlesparticlesystemcloudpoint

How do you set Particles to known positions?

I would like to be able to draw point clouds using particles. To do this I need to be able to set an array of particles to a known position, zero velocity, emit them and have them last forever. However, I cannot the setting of the position to work.

My set up is as follows.

  • Empty GameObject with a ParticleSystem attached

  • Duration = 1

  • Looping = true

  • Start Lifetime = 10

  • Start Speed = 0

  • Start Size = 0.1

  • Emission is turned off

  • Shape is turned off

  • Renderer is turned on.

The following script is attached to the GameObject

 using UnityEngine;
 using System.Collections;

 public class PointCloud : MonoBehaviour {
 
     ParticleSystem.Particle[] cloud;
 
     void Start ()
     {    
         float v = 1.0f;
         cloud = new ParticleSystem.Particle[4];
         cloud[0].position = new Vector3(v,v,v);
         cloud[1].position = new Vector3(-v,v,-v);    
         cloud[2].position = new Vector3(-v,v,v);
         cloud[3].position = new Vector3(v,v,-v);
         
         for(int ii = 0; ii < cloud.Length; ++ii)
         {
             ParticleSystem.Particle p = cloud[ii];
             p.color = Color.red;
             p.velocity = Vector3.zero;
             p.angularVelocity = 0.0f;
              p.rotation = 0.0f;
             p.size = 0.1f;
             p.lifetime = 1.0f;
             p.randomValue = 0.0f;
         }
         
         particleSystem.SetParticles(cloud, cloud.Length);
         particleSystem.Emit(cloud.Length);
     }
 }


  • All that happens though is I get an single (or more, I can't tell) particle at the system's origin.

  • The particle has the size and color set in the inspector and not that in the script.

  • If I add a Shape then I do get 4 points, but at random locations and not the locations specified.

  • Also, if I get the particles after setting them, they do have the positions and other characteristics I specified.

  • I am using Unity 3.5.2f2

These posts indicate that it is possible:

  • PointCloud-Shader

  • Setting Particle Position Does Not Seem To Work

  • As does the documentation

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
10
Best Answer

Answer by Robert-Castle · Jun 03, 2012 at 11:35 AM

Finally got it working. Here is a minimal example with no error checking:

 using UnityEngine;
 using System.Collections;

 public class PointCloud : MonoBehaviour
 {
     ParticleSystem.Particle[] cloud;
     bool bPointsUpdated = false;
     
     void Start ()
     {
     }
     
     void Update () 
     {
         if (bPointsUpdated)
         {
             particleSystem.SetParticles(cloud, cloud.Length);
             bPointsUpdated = false;
         }
     }
     
     public void SetPoints(Vector3[] positions, Color[] colors)
     {        
         cloud = new ParticleSystem.Particle[positions.Length];
         
         for (int ii = 0; ii < positions.Length; ++ii)
         {
             cloud[ii].position = positions[ii];            
             cloud[ii].color = colors[ii];
             cloud[ii].size = 0.1f;            
         }
 
         bPointsUpdated = true;
     }
 }

Attach this script to a GameObject with a Shuriken particle system, and set the particle system as follows to make it inert:

  • Looping false

  • Play On Awake false

  • Max Particles*to the max number of particles you want*

  • Turn off everything except Renderer

In the Renderer:

  • Sort Mode By Distance

  • Cast Shadows false

  • Receive Shadows false

This tutorial was very enlightening and awesome: Graphs - visualizing data

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 MountDoomTeam · Feb 19, 2013 at 12:32 PM 0
Share

I followed your example exactly and I couldn't see anything! I checked through the checklist twice and I copied the code to an object with Shuriken particle system. -okay this page is awesome indeed http://catlikecoding.com/unity/tutorials/graphs/

avatar image
2

Answer by Berenger · Jun 01, 2012 at 04:37 PM

I've never tried to do that with the shuriken system, but from the lightning bolt example you should

  • Emit 4 particles.

  • Store them into an array with GetParticles.

  • Apply the modifications.

  • Use SetParticles to assign them back.

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 Robert-Castle · Jun 03, 2012 at 11:01 AM 0
Share

Thanks, that example got me on the right path.

avatar image sergiobd · Apr 11, 2017 at 07:49 PM -1
Share

Do you $$anonymous$$d sharing the link of the example you are talking about?

avatar image
1

Answer by Artifact-Jesse · Nov 21, 2018 at 08:05 AM

For those stumbling across this in Unity 2018.x, check out my answer here with a functional example. http://answers.unity.com/answers/1573665/view.html Thank you to all the answers here, you helped me find a solution!

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 crogers · Jul 18, 2012 at 09:08 PM

I am trying the same thing. Although I can call SetParticles() without error, I do not see my particles and GetParticles() returns nothing, even on a "stock" ParticleSystem that is visibly emitting particles.

Do GetParticles() and SetParticles() work (using Javascript and UnityPro 3.5.3)?

 function emitTex () {

var mult : float = 0.5; var x : int; var y : int; var c : Color; var p : ParticleSystem.Particle[]; p = new ParticleSystem.Particle[4096]; var i : int = 0; for (x = 0 ; x < map.width ; x = x + 1 ) { for (y = 0 ; y < map.height ; y = y + 1 ) { c = map.GetPixel(x,y); p[i].position = Vector3(x mult, y mult, 0 ); p[i].color = c; p[i].size = 4.0; Debug.Log(i+" "+p[i].size.ToString()+" "+p[i].position.ToString()+" c="+c.ToString()); i = i + 1; } } ps.Play(); particleSystem.SetParticles(p,p.Length); Debug.Log("made "+i+" particles\n"); //ps.Play(); var pp : ParticleSystem.Particle[]; var n : int; n = particleSystem.GetParticles(pp); Debug.Log("got "+n+" particles\n"); flag = 0; }

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 crogers · Jul 18, 2012 at 09:10 PM 0
Share

(by the way, my code showed up correctly in the preview but gets mangled in the post.....)

avatar image Robert-Castle · Jul 19, 2012 at 08:23 AM 0
Share

Your array pp needs to be assigned first, and be large enough to hold the required number of particles. If pp = 10 and particleSystem = 100, you will get back 10. If pp = 10000 and particleSystem = 100, you will get back 100. Use particleSystem.particleCount to find out how many there currently are.

var pp : ParticleSystem.Particle[];

var n : int;

pp = new ParticleSystem.Particle[particleSystem.particleCount];

n = particleSystem.GetParticles(pp);

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Teleporting old particle system 0 Answers

Move to a clicked point? 1 Answer

Optimized Coin Party using Particle System.. 0 Answers

I want to pause and clear a particle system and be able to start it again, but I am using the Sparkle Rising particle which has no Particle System? 1 Answer

How do I make instantiated particles inherit Transform movement from their parent object? 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