• 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 sir_ver · May 08 at 09:52 AM · ontriggerenterbulletoncollisionenter

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.

Comment
Add comment · Show 1
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 MrRightclick · May 08 at 11:33 AM 0
Share

Helping would be easier if we could see your OnTriggerEnter code.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tormentoarmagedoom · May 08 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!

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

109 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

Related Questions

Have bullets be destroyed when they collide with ANY collider 1 Answer

OnCollisionEnter vs OnTriggerEnter for performance 1 Answer

OnTriggerEnter() not firing for mutliple objects 0 Answers

How to detect collisions in C# 2 Answers

OnTriggerEnter not called after importing a package that works fine 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges