Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Nexonity · Jan 21, 2014 at 03:27 PM · collidertransformtriggerconvert

Get the colliders transform (?)

I'm not really sure how to put this but i get a NullReferenceException error in the AITrigger script, probably because the collider doesn't have a transform attached to it but i need to access the transform on the same gameobject as the collider is attached to. The question is how? Here is the scripts (Only relevant parts):

AITrigger.cs

     void OnTriggerEnter(Collider other) {
         if (IsEnemy == "Yes") {
             if(other.gameObject.tag == "Friendly" || other.gameObject.tag == "Player") {
                 PlayerPrefs.SetString(gameObject.name, "Yes");
                 AIPath AIPath = GetComponent<AIPath>();
                 sendthis = other.transform;
                 AIPath.SetTarget(sendthis);
             }
         }
         if (IsEnemy == "No") {
             if(other.gameObject.tag == "Enemy") {
                 PlayerPrefs.SetString(gameObject.name, "Yes");
                 AIPath AIPath = GetComponent<AIPath>();
                 sendthis = other.transform;
                 AIPath.SetTarget(sendthis);
             }
         }
     }

AIPath.cs

 public void SetTarget (Transform x) {
         target = x;
 }
Comment
Add comment · Show 7
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 brycedaawg · Jan 21, 2014 at 03:42 PM 0
Share

This might come off as a silly question, but have you tried using other.transform? A Collider will always have a transform attached to it.

avatar image Nexonity · Jan 21, 2014 at 03:45 PM 0
Share

Nope same thing, NullReferenceException: Object reference not set to an instance of an object AITrigger.OnTriggerEnter (UnityEngine.Collider other) (at Assets/FPS $$anonymous$$it Version 2.0/_CustomAssets/Scripts/Network C#/AITrigger.cs:24)

avatar image KiraSensei · Jan 21, 2014 at 03:46 PM 0
Share

Is THIS or THAT that you are looking for ?

avatar image Jamora · Jan 21, 2014 at 03:47 PM 0
Share

Which line is 24? Have you read the Answers here on UA that (try their hardest to) explain null reference exceptions? (This one and this one)

avatar image Nexonity · Jan 21, 2014 at 03:58 PM 0
Share

$$anonymous$$iraSensei: If is not too much to ask for, could you please show me an example? There is non available at the docs.

Jamora: Line 24 is line 7. Yes i have read the second link and as i said in my question its probably because the collider doesn't have a transform attached to it.

Show more comments

1 Reply

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

Answer by Nexonity · Jan 21, 2014 at 04:46 PM

Somehow after refreshing the script it did work... Anyway thanks for all the suggestions!

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 KiraSensei · Jan 21, 2014 at 06:45 PM 0
Share

What do you mean by refreshing the script ? A script can't be "refreshed", it is modified, or not, and compiled.

avatar image Nexonity · Jan 21, 2014 at 06:52 PM 0
Share

Restarted Unity, rightclicked the script and then refresh.

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

22 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

Related Questions

Move a wall up when player steps on trigger 2 Answers

convert a collider array to a list transform 1 Answer

Check if another object exist in a position before respawning 1 Answer

Convert type `UnityEngine.Collider' to `string'? 1 Answer

Destory/Collect object to open door 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