Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 lavarith · Sep 20, 2016 at 08:29 AM · networkingclient-server

NullReference Exception FindLocalObject C#

I have a PlayerItem script that manages object pickup and dropping for each player across a network. When I spawn the objects to the environment, I do it via a script called ItemManager on a GameObject by the same name. That item is a prefab that is spawned via NetworkSpawn. I have inventory working for the most part. Items are properly spawned as children of the ItemManager. A user can pick up items, they're properly sorted into stacks on each user via [Client] and [Command] functions. This is all reflected as far as I can tell on both the client and server in the inspector, too.

Now, here's the problem. When a player 'drops' an item, I would like to child it back to the ItemManager gameobject. However, every effort to get the object via the netId has returned a null reference exception. I've even checked the inspector during runtime and the Network Id associated with ItemManager is the same that is output by Debug.Log.

         overUI = EventSystem.current.IsPointerOverGameObject();
         // Pick up item (Move this!)
         Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
         RaycastHit _hit;
 
         if(Input.GetButtonDown ("Left Click") && !overUI){
             if (Physics.Raycast(ray, out _hit, 100)){
                 if(_hit.collider.gameObject.tag == "Item"){
                     Debug.Log ("Item Clicked");
                     itemClicked = _hit.collider.gameObject;
                 }else{
                     itemClicked = null;
                 }
                 // Drop an item
                 if(_hit.collider.gameObject.tag == "Ground"){
                     Debug.Log ("Clicked Ground");
                     NetworkInstanceId localItemManagerNID = GameObject.Find ("ItemManager").GetComponent<NetworkIdentity>().netId;
                     Debug.Log ("local Item Manager NID: " + localItemManagerNID);
                     Debug.Log ("Game Object: " + ClientScene.FindLocalObject(localItemManagerNID));
                     DropItem (GetComponent<NetworkIdentity>().netId, localItemManagerNID, _hit.point);
                 }
             }
         }

The local item manager NID shows up as "2" in the console. The game object that is found via ClientScene.FindLocalObject() is immediately returned as Null. My standard practice is then to send this information to a [Client] function followed by a [Command] function which updates syncvars on the clients. Having a value that immediately references to a null gameobject doesn't make sense and clearly wont help once it returns to the clients.

Any help would be appreciated.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by UNDERHILL · Sep 21, 2016 at 04:26 PM

I think you might have a synchronicity issue. Maybe put this in an IEnumerator and yield the "LocalItemManagerNID =" ?

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Send a file using NetworkServer class. 0 Answers

How to watch in client applications what it is happening in the server one? 0 Answers

UNET Different size of spawned object on host and client 1 Answer

Need help understanding ClientRpc from Unity Networking tutorial,Question about clientrpc 1 Answer

Networked Objects not appearing on Client when Client loads scene first 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