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
1
Question by GameGuy · Apr 23, 2018 at 12:36 PM · scripting problemparticlesystemdocumentationonparticlecollision

How to use OnParticleTrigger correct?

I have a Gameobject and a ParticleEffect, the ParticleEffect has activated "Collision" and "Triggers". "Triggers" is set to kill on Enter when the GameObject enters. Thats all working fine the particles get killed. But how do I check for simple things like the tag of the Gameobject in script?

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

Answer by richardkettlewell · Apr 24, 2018 at 07:11 PM

You can see an example script here: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnParticleTrigger.html

Comment
Add comment · Show 3 · 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 GameGuy · Apr 25, 2018 at 11:44 AM 0
Share

$$anonymous$$aybe I am to stupid but I cant find there how to use "Trigger>>Enter>>$$anonymous$$ill"

avatar image richardkettlewell ♦♦ · Apr 25, 2018 at 12:55 PM 1
Share

Oh yes, apologies, $$anonymous$$ill is automatic and doesn't hook up to script.

To hook up to script, simply assign the Enter condition to callback ins$$anonymous$$d.

Now you can detect these events in script. To preserve the kill behavior, do it via script by setting the Particle.remainingLifetime property in the callback.

avatar image GameGuy richardkettlewell ♦♦ · Apr 25, 2018 at 02:05 PM 0
Share

No worries, Thanks for your time now I understand :)

avatar image
2

Answer by richardkettlewell · Apr 23, 2018 at 01:07 PM

Hi, unfortunately OnParticleTrigger doesn't provide any way to know which object the particle triggered. It's on our roadmap to add in the future.

Comment
Add comment · Show 9 · 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 GameGuy · Apr 23, 2018 at 01:27 PM 0
Share

If thats true for what is ParticleSystem>>Triggers>>Colliders else used? Because If I add a moving GameObject there and set "Enter" to kill, the Particles will only get killed by that GameObject and if you hover over ParticleSystem>>Triggers>>Colliders the Infobox-Tooltip says "The list of collision shapes to use for the trigger"

avatar image richardkettlewell ♦♦ GameGuy · Apr 23, 2018 at 01:45 PM 0
Share

yes that is the list used. i simply mean that, when the callback is triggered, if you have 1 particle and 2 gameobjects, there is no way for you to find out which of the 2 gameobjects the particle triggered.

if you only have 1 gameobject in your list, then it's easy. just use ParticleSystem.trigger.GetCollider(0)

avatar image GameGuy richardkettlewell ♦♦ · Apr 24, 2018 at 04:12 PM 0
Share

Thanks for your help Richard. I am not able to get that(ParticleSystem.trigger.GetCollider(0)) working correct, my debug.log is firing all the time and there is no GameObject to collide with, only particles from the ParticleSystem itself if thats possible. Would you please so kind and hand out a code snippet that prints a Debug.Log when Trigger>>Enter>>$$anonymous$$ill is activated?

avatar image adambossy · May 10, 2020 at 01:25 AM 0
Share

Hey @richardkettlewell, any updates on this?

avatar image richardkettlewell ♦♦ adambossy · May 10, 2020 at 12:34 PM 0
Share

Not really, but we have been discussing it again internally. A question for you: what would happen if more than one collider caused the trigger? Ie overlapping colliders. Should the callback be able to get both? Or is one enough?

avatar image adambossy richardkettlewell ♦♦ · May 10, 2020 at 10:13 PM 0
Share

Hey Richard, cool to hear that you're discussing it internally!

Both would be best, in case either object needs to react to the collision in a specific way.

For context, my use case for this is: I have a particle system that interacts with the world in a variety of collision behaviors. Its particles bounce off of world objects and they cause damage to the players and NPCs. I hope to add more interactions, such as a bomb going off that destroys particles.

The particle collision callbacks are limiting because OnParticleCollision(GameObject o) provides the game object but not the particles, and OnTriggerEnter/Inside() will provide the particles with GetTriggerParticles, but not provide the game object. I'm almost entirely dependent on the Particle System's built in Collision and Triggers module.

I'm not sure how the Unity collision system internals work, but I imagine both the colliding particle and the GameObject being collided with are available, and I'd imagine all the colliding objects are readily available to pass back to each callback function.

Show more comments
avatar image
2

Answer by Lokym · Jun 10, 2019 at 04:18 PM

I know this post is a bit old, but I found a solution to detect a GameObject when the particle triggered something. You can Instantiate a collider at the position of the particle where it hit the gameObject, then use a OnTriggerEnter or Physics.OverlapBox / OverlapSphere or all that kind of things to do what you want.

 // The collider to Instantiate. You can also use Resources.Load<GameObject>(). "
  public GameObject colliderGO;
 
     void OnParticleTrigger()
     {
         ParticleSystem ps = GetComponent<ParticleSystem>();
 
         // particles
         List<ParticleSystem.Particle> enter = new List<ParticleSystem.Particle>();
 
         // get
         int numEnter = ps.GetTriggerParticles(ParticleSystemTriggerEventType.Enter, enter);
 
         // iterate
         for (int i = 0; i < numEnter; i++)
         {
             ParticleSystem.Particle p = enter[i];
         // instantiate the Game Object
             Instantiate(colliderGO, p.position, Quaternion.identity);
             enter[i] = p;
         }
 
         // set
         ps.SetTriggerParticles(ParticleSystemTriggerEventType.Enter, enter);
     }


NOTE: You have to set the SimulationSpace in the ParticleSystem to "World" to get the good p.position. Also, maybe the ParticleSystemTriggerEventType.Enter won't be accurate enough, and you will need to choose the ParticleSystemTriggerEventType.Inside, but be careful because it will instantiate a lot of gameObject.

And then, when your Game Object in instantiate, you do:

   private void OnTriggerEnter(Collider other)
     {
        // what you want to do
       // to avoid a stack of GameObjects
       Destroy(gameObject);
     }


Hope this still can help.

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 denholmspurr · Apr 24, 2020 at 03:04 AM 0
Share

Really think this might be the solution i'm looking for but I'm struggling with the last bit. I'm pretty new to this so bare with!

"And then, when your Game Object in instantiate, you do:" this bit doesn't make sense.

Does that bit of code go on the Game Object you want to detect? So for example if the particle was trigger by an enemy I'd put the script on that enemy?

private void OnTriggerEnter(Collider other) { // what you want to do // to avoid a stack of GameObjects Destroy(gameObject);

Is the destroy command destroying the Collider? I presume that's the point? but that's currently named other. can't get y head around this ;/

avatar image
-2

Answer by shadowpuppet · Apr 23, 2018 at 12:50 PM

if you just want to know the name of the gameObject

 void OnTriggerEnter(Collider collider) {
 print (collider.gameObject.name);//or
 print (collider.gameObject.tag);// I think
 
 //if you want the particles to only get triggered on certain tags
 
 void OnTriggerEnter(Collider other) {
 if(other.CompareTag == ("Player")){
 //DoSomethingHere
 }
 }
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 GameGuy · Apr 23, 2018 at 01:21 PM 0
Share

Ok Thanks, but I was talking about Particlesystem>>OnParticleTrigger and not about OnTriggerEnter!

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

149 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

Related Questions

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

Particle Collision not detected 1 Answer

Code for destroying object with particle and move to the next object. 1 Answer

Using a Burst in a script 3 Answers

Animating key on AnimationCurve in real time 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