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 StarCrossedGaming · Feb 26, 2015 at 06:30 PM · errorreferenceexception

Stupid "Reference Exception Error"

Hello! I am getting quite annoyed with this error. I added something to my multiplayer FPS game and have not touched this piece of code that had been working for quite a while, then I started getting this error every time I started to spawn my character. It is really annoying, here is the code.

public void SpawnAssaultSoldier(int teamID) { this.teamID = teamID; hasPickedTeam = true; AddChatMessage(PhotonNetwork.player.name + " Joined the Game");

     if(spawnSpots == null) {
         Debug.LogError ("Say What!");
         return;
     }
     
     SpawnSpot mySpawnSpot = spawnSpots[ Random.Range (0, spawnSpots.Length) ];
     GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("PlayerController.Assault", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);


     ((MonoBehaviour)myPlayerGO.GetComponent("MouseLook")).enabled = true;
     Debug.Log ("Mouse Look Enabled for " + PhotonNetwork.player.name);
     ((MonoBehaviour)myPlayerGO.GetComponent("PlayerMovement")).enabled = true;
     ((MonoBehaviour)myPlayerGO.GetComponent("PlayerShooting")).enabled = true;
     ((MonoBehaviour)myPlayerGO.GetComponent("MouseLock")).enabled = true;
     ((MonoBehaviour)myPlayerGO.GetComponent("ScopeControl")).enabled = true;

     
     myPlayerGO.GetComponent<PhotonView>().RPC ("SetTeamID", PhotonTargets.AllBuffered, teamID);

     standbyCamera.SetActive(false);
     myPlayerGO.transform.FindChild("Main Camera").gameObject.SetActive(true);
     //myPlayerGO.transform.FindChild("MiniMapCamera").gameObject.SetActive(true);
 



 }







The error message :
NullReferenceException: Object reference not set to an instance of an object NetworkManager.SpawnAssaultSoldier (Int32 teamID) (at Assets/NetworkManager.cs:630) NetworkManager.OnGUI () (at Assets/NetworkManager.cs:396)

I'm trying to release this version of my game within 48 hours, so please try to help me quickly. Also note that I did not paste all my code into this box, just the stuff where the error was, thank you all.

Comment
Add comment · Show 2
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 psykojello2 · Feb 26, 2015 at 06:47 PM 0
Share

Does your SpawnAssaultSolider game object need to be hooked up as a property of another script? $$anonymous$$aybe that connection broke and your network manager does not know what to use as you SpawnAssaultSolider.

Sorry if that wasn't helpful, it's not completely clear what the problem is.

avatar image Jessespike · Feb 26, 2015 at 07:12 PM 2
Share

what line of code is 630?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by spiceboy9994 · Feb 26, 2015 at 08:09 PM

Since you copied just the piece of the code that might have the issue, not easy to tell about the real problem. But I can do a hard guess:

Object reference not set to an instance of an object NetworkManager.SpawnAssaultSoldier

This means that the code tried to find the method SpawnAssaultSoldier within the object of type NetworkManager. I suppose it is a class name right?. Did you tried to call that method within the same NetworkManager class? If that's the case the call will be simply SpawnAssaultSoldier(id) or this.SpawnAssaultSoldier(id). If you tried to call the method from another component, since your method is not STATIC you should call something like:

 gameObject.GetComponent<NetworkManager>().SpawnAssaultSoldier(id);

where gameObject is the Game Object that has the NetworkManager monobehavior attached to it.

If you want to call the method by doing NetworkManager.SpawnAssaultSoldier(id), your method MUST be declared as static, but it may require other changes on your code (since static methods cannot call not static methods).

Hope this points you on what the real problem is.

Comment
Add comment · Show 4 · 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 StarCrossedGaming · Feb 26, 2015 at 08:25 PM 0
Share

The network manager is attached to an empty Gameobject within the scene. There is a Prefab called " PlayerController.Assault " which, you are correct, is a class type. The only error there is with the $$anonymous$$ouse Look, that is the line of code which is triggering an error. When I delete that line of code, the player can spawn again, which works, but is not perfect. I need the $$anonymous$$ouseLook to be enabled on spawn. I have a $$anonymous$$ouse Look component disabled on the prefab, which when the player spawns it is enabled. I have had no problem with this until now. (Of course is when my release date is -_-)

Hopefully this gives you some more information.

avatar image spiceboy9994 · Feb 26, 2015 at 08:32 PM 0
Share

So just to be clear, are you trying to call that Network$$anonymous$$anager.SpawnAssaultSoldier from wihin your PlayerController.Asault class... if this is the case the gameObject.GetComponent().SpawnAssaultSoldier(id); is the approach to follow. Just be sure that the gameObject points to your empty Gameobject that has the Network$$anonymous$$anager script attached.

Regards

avatar image StarCrossedGaming · Feb 26, 2015 at 08:49 PM 0
Share

Sort of, one thing is that also within the Network $$anonymous$$anager, there is a GUI button that when you click it is triggers the void, and the void locates PlayerController.Assault (with photon, everything that is instantiated is located in a folder in the assets) the prefab is then instantiated, with the modifications that the void provides.

avatar image spiceboy9994 · Feb 26, 2015 at 09:08 PM 0
Share

How about pasting the line where you are calling that method? and the class definition where that method call is placed?

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

NullReferenceException - With Network PlayerSpawn 0 Answers

Null Reference Exception Error 1 Answer

NullReferenceException: object not in inspector? 0 Answers

Despawner script returns null reference exception. 0 Answers

Help with error: UnassignedReferenceException 5 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