Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 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
2
Question by lumbo1379 · Apr 13, 2018 at 06:38 PM · collisioncolliderparticlesystemparticle collisiononparticlecollision

Getting the position/intersection of collided particles

The purpose of this code is to create a fire explosion effect at the intersection of a particle when it collides with a plane. The only solutions I could find to gathering the intersection point was by using GetCollisionEvents and ParticleCollisionEvent. Although, when a ParticleCollisionEvent is added to _collisionEvents the function GetCollisionEvents seems to set the collider using an obsolete method. Is there anyway around this or any other solutions in gathering a particles point of intersection when a collision occurs? I have also looked at using ParticlePhysicsExtensions.GetCollisionEvents, but this is also obsolete.

 public GameObject _ExplosionEffect;
 public ParticleSystem _FireEmbers;

 private List<ParticleCollisionEvent> _collisionEvents;

 private void Start()
 {
     _collisionEvents = new List<ParticleCollisionEvent>();
 }

 private void OnParticleCollision(GameObject other)
 {
     _FireEmbers.GetCollisionEvents(other, _collisionEvents);

     CreateExplosion(_collisionEvents[0]);

 }

 private void CreateExplosion(ParticleCollisionEvent particle)
 {
     _collisionEvents.Clear();

     GameObject effect = Instantiate(_ExplosionEffect, particle.colliderComponent.transform);
     effect.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
     effect.AddComponent<DestroyEffect>();
 }

alt text

System.InvalidOperationException: collider property is deprecated. Use colliderComponent instead, which supports Collider and Collider2D components

unians.png (153.7 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by bunnynsnake · Apr 13, 2018 at 09:02 PM

This should work...

 using UnityEngine;
 using System.Collections;
 
 public class OnParticleCollisionAlt : MonoBehaviour { 
 public GameObject myExplosion; 
 public GameObject prefabExplosion;
 private ParticleSystem.CollisionEvent[] collisionEvents = new ParticleSystem.CollisionEvent[16];
  void OnParticleCollision(GameObject other) {
      int safeLength = particleSystem.safeCollisionEventSize;
      if (collisionEvents.Length < safeLength)
          collisionEvents = new ParticleSystem.CollisionEvent[safeLength];
      int numCollisionEvents = particleSystem.GetCollisionEvents(other, collisionEvents);
      int i = 0;
      while (i < numCollisionEvents) {
          Vector3 collisionHitLoc = collisionEvents[i].intersection;
          myExplosion = Instantiate (prefabExplosion, collisionHitLoc, Quaternion.identity) as GameObject;
          i++;
      }
  }
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 lumbo1379 · Apr 13, 2018 at 09:39 PM 1
Share

The stored event still contains the error System.InvalidOperationException: collider property is deprecated. Use colliderComponent ins$$anonymous$$d, which supports Collider and Collider2D components. (The one from the screenshot). As there is this error, all intersections are stored at 0, 0, 0 , so all effects instantiate here.

Also: ParticleSystem.CollisionEvent is obsolete particleSystem.safeCollisionEventSize is obsolete ParticleSystem.CollisionEvent[] collisionEvents = new ParticleSystem.CollisionEvent[16] using an array is obsolete (recommends a list)

avatar image triangle4studios lumbo1379 · Jan 24, 2021 at 05:47 PM 0
Share

Note: In $$anonymous$$any Cases, you can get away without using a loop in particle collision.

$$anonymous$$ake sure you are placing OnParticleCollision() inside a script that is ON the particle collider object. This is key. Because the other is the object the particles collide with, and it temporarily has a particle system added to it on Collision.


The particle system "part" in part.GetCollisionEvents(other, collisionEvents); is the system that created the particles. Other is the gameObject on which those particles died. They are mutually exclusive.

When you separate them you will find it all works.

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

132 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

Related Questions

Why can't I add non-prefab colliders to a particle effects triggers list? 0 Answers

How to destroy object when it collides particle 1 Answer

Fire Collision detection 1 Answer

can we attach a collider for each particle emitted by a emitter 1 Answer

Let Particles sit on Collider without triggering callback - OnParticleCollisionEnter? . 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