- Home /
OnTriggerEnter conflict
So I have a 2 Agents. Agent 1 is shooting at agent 2. The bullet is a trigger and the agent has a collider. I have a bulletController script and a AgentController.
My problem:
If one agent hits the other with a bullet I get NullReferenceException, because in the agents script I have a OnTriggerEnter and I look there if the bullet hits. But the agent doesn't have a trigger. So would it work if I set the method to onCollisionEnter, even if the bullet is a trigger? How can I solve this? But I do not want to place the Ontriggerenter to the bullet script.
Helping would be easier if we could see your OnTriggerEnter code.
Answer by tormentoarmagedoom · May 08, 2019 at 10:08 AM
Hello!
You are little bit copnfused :D (its normal collides are confusing sometimes)
First, i recommend you to spend 30 minutes reading the Unity Manuals
https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
And all its variants (enter, stay, exit, trigger, collision....)
I'm sure you will find some sentence that will make you realize something you didnt know or didnt understood.
Then, i think best solution is to make the bullet a trigger collider, and only detect from inside the bullet if the triigerEnters some collider with tag enemy or player or something like this.
Bye!
Your answer
![](https://koobas.hobune.stream/wayback/20220612200936im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Have bullets be destroyed when they collide with ANY collider 0 Answers
OnCollisionEnter vs OnTriggerEnter for performance 1 Answer
Delayed Collisions Bug (includes video demonstration) 1 Answer
How to change the direction of spawning of an object just before colliding a wall like object?? 2 Answers
2 objects collide, need to destroy one 2 Answers