Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
0
Question by ScPlays · Dec 04, 2017 at 08:10 AM · scripting problemcollisionparticlesparticlesystem

Finding Particle Information Upon Collision

I have just a short question, it doesn't seem to be addressed anywhere so I'm not entirely sure if it's possible, here's my problem:

I have a system set up where particles will collide with a GameObject and deal damage to it. The particles in question shrink as they float through the air. I'm trying to figure out how to find out what the size of the particle is at the time of collision. For reference, it is a constant beam effect, so I can't simply take the starting size. I would like for the player to have to get closer to the enemy GameObject to deal more damage, since the particles would be larger upon collision. (There are likely other ways to achieve this effect, but finding the size of the particle at the time would be the cleanest way to do it.)

TL;DR: How do I find out information about a particle upon collision with a GameObject? (ie: the current size, not the startSize)

Thanks in advance.

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 Dave-Hampson ♦♦ · Jan 08, 2018 at 03:17 PM 0
Share

I have a system set up where particles will collide with a GameObject and deal damage to it. The particles in question shrink as they float through the air. I'm trying to figure out how to find out what the size of the particle is at the time of collision. For reference, it is a constant beam effect, so I can't simply take the starting size.

When you say 'particle' I presume you are not referring to the Unity particle system, but some kind of system you have set up yourself?

In that case, if you are tracking the size of your particles, can you not simply read out the size of the particle on collision with the GameObject?

avatar image ScPlays · Jan 08, 2018 at 09:02 PM 0
Share

I am in fact using the shuriken particle system built in to unity. I have colliders set up on the particles, however I can't figure out how to find information about the particles the way I could with two physics objects.

2 Replies

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

Answer by richardkettlewell · Jan 09, 2018 at 12:30 PM

Unfortunately you only have access to a limited amount of data inside the OnParticleCollision callback. You can see all the available data here: https://docs.unity3d.com/ScriptReference/ParticleCollisionEvent.html

(and a working example here: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnParticleCollision.html)

There is no way to find out the size of the colliding particles using this mechanism, but it sounds like you have some other way of knowing the start size? If that's the case, you presumably have access to a Particle (https://docs.unity3d.com/ScriptReference/ParticleSystem.Particle.html), so you can use the GetCurrentSize method on that structure.

If that's not actually true, then all I can tell you is that it's on our roadmap to improve this API, but currently it is indeed quite limited.

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 ScPlays · Jan 11, 2018 at 05:54 AM 1
Share

I see. Thanks for the input, I'll have to figure out some other way then. I would absolutely love to see these limitations removed in the future, though.

avatar image Fluidmind · Feb 16, 2021 at 08:44 PM 0
Share

This was 3 years ago, and the API remains unchanged. You mentioned it was on the roadmap, but I fear this may have been put on the wayside for features such as DOTS. Guess I won't be using the particle system for what I want afterall.

avatar image
0

Answer by Josiah_Kunz · Aug 03, 2021 at 02:52 PM

This is an old post, but it still comes up when you Google things like "get particle collision information". I needed a solution for particles as damage sources hitting an enemy or portal:

  1. Make sure the collisions module is checked on your ParticleSystem.

  2. Make sure Send Collision Messages is also checked on the collisions module.

  3. On your target (e.g., enemy), make sure you have a Rigidbody and either a collider on the target or composite collider children. Colliders can be confusing to people, but here's how mine is set up:

Collider that triggers from all collisions but does not move. 4. On your target, place the following script:

 public Rigidbody rigidbody;
 
 void OnParticleCollision(GameObject other) {
 
    // Get particles
    ParticleSystem particleSystem = other.GetComponent<ParticleSystem> ();
    if (particleSystem == null)
       return;
 
    // Here's the meat of the problem
    ParticleSystem.Particle[] allParticles = new ParticleSystem.Particle[particleSystem.particleCount];
    particleSystem.GetParticles(allParticles);
    Bounds particleBounds;
    for(int i=0; i<allParticles.Length; i++)
       foreach(Collider collider in rigidbody.GetComponentsInChildren<Collider>()){
                 if (collider.isTrigger)
                     continue;
                 particleBounds = new Bounds(allParticles[i].position,
                                             allParticles[i].GetCurrentSize3D(particles));
                 if (collider.bounds.Intersects(particleBounds)){
                     // Manipulate particles here! I just kill them for visual confirmation
                     allParticles[i].remainingLifetime = -1;
                     break;
                 }
             }
         }
         particles.SetParticles(allParticles);
 }

This lets you know if your particles are within the collider (which is what caused OnParticleCollision to be called in the first place).

Edit 1: typos

Edit 2: Switched answer from a me-specific solution to a general solution


tmp.png (302.7 kB)
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

171 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 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 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 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 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 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 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 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

Transforming and playing particle effects? Help! 1 Answer

Destroy multiple GameObject when Particles collide 1 Answer

Particles causing a weird effect on the surface they collide with 0 Answers

How to make OnParticleCollision affect multiple GameObject 1 Answer

Particle System Emission Rate Scriptt 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