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 Domo23000 · Dec 30, 2014 at 08:16 PM · collisionontriggerentertagrpcother

OnTriggerEnterProblem

i have a script to call an RPC fuction when i collide with a flag in a ctf game. but when i collide with it an error comes up

NullReferenceException: Object reference not set to an instance of an object Flag.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/ObjectScripts/Flag.cs:28)

here's the script

     NetworkManager manager;
     public bool isRed;
 
     void Start () 
     {
         manager = gameObject.GetComponent<NetworkManager> ();
         if(isRed)
         {
             gameObject.GetComponentInChildren<InteractiveCloth>().renderer.material.color = Color.red;
             gameObject.GetComponentInChildren<Light>().color = Color.red;
         }
         else
         {
             gameObject.GetComponentInChildren<InteractiveCloth>().renderer.material.color = new Color(0, 0.5f, 0);
             gameObject.GetComponentInChildren<Light>().color = new Color(0, 0.5f, 0);
         }
     }    
 
 void OnTriggerEnter(Collider other) 
     {
         if(other.tag == "Player")
         {
             manager.GetComponent<PhotonView>().RPC("FlagHolderChange", PhotonTargets.AllBuffered, other.gameObject, isRed);
         }
     }
Comment
Add comment · Show 4
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 Glurth · Dec 30, 2014 at 08:19 PM 0
Share

I would suspect that one of your GetComponent Functions is not finding the component you want, and returning a null value. The line number in the error does not exist in this code, so it's hard to figure out which one.

avatar image Domo23000 · Dec 30, 2014 at 09:13 PM 0
Share

the error is in the rpc call

avatar image Glurth · Dec 30, 2014 at 09:48 PM 1
Share

then I suggest you break the call up into a few separate lines to find the problem: e.g.

 PhotonView pv=manager.GetComponent<PhotonView>();
 if(!pv) //checks for null
   Debug.Log("PhotonView Get failed");



if this test fails- I'd double check your hierarchy & components in the editor.

avatar image Domo23000 · Dec 30, 2014 at 11:59 PM 0
Share

Thanks man. I really should've done the tests before asking anything. The problem was the manager wasn't found but i fixed it with

manager = GameObject.FindObjectOfType ();

ins$$anonymous$$d of

manager = gameObject.GetComponent ();

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jmgek · Dec 30, 2014 at 08:27 PM

Don't use Tags when you can, it is more expensive when you build out.

  void OnTriggerEnter (Collider col)
         {
             if(col.gameObject.name == " ")
             {
             }
         }
 



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 Glurth · Dec 30, 2014 at 09:53 PM 0
Share

I don't understand what this example is trying to show, nor how it relates to the OP's question.

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

27 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

Related Questions

How to make game like Hoops Stack 1 Answer

Using the OnTriggerEnter ∁aring tags correctly. 1 Answer

AI Attack Not Working! W/Video 1 Answer

Checking trigger collision on other objects? 2 Answers

Help With Colliders 3 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