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 Naeja · Oct 20, 2014 at 04:29 AM · networkingnetworkphoton

Level Loading Over A Network: Level Loaded Event returning a null value?

Hey so I'm trying out my first ever multiplayer game so far I've found some really great resources and I'm using the awesome free Photon Unity Networking extension. Basically my problem is this, once the player connects to/ initializes the server I need them to be taken from the menu screen to the "game" scene and once that happens, I want to instantiate the players character.

I've got a NetworkManager script which works more or less exactly as outlined in this article here is my method for loading level once the player connects to the server

 //Load Level so that the network does not send any messages or do anything funny while level is loading
 private void LoadLevel(string level, int levelPrefix){
     //Stop sending data in default channel
     Network.SetSendingEnabled(0, false);
     //Stop recieving data
     Network.isMessageQueueRunning = false;
     //Load level
     Network.SetLevelPrefix(levelPrefix);
     Application.LoadLevel(level);
     StartCoroutine(Stall(2));
     //Enable sending and recieving once again
     Network.isMessageQueueRunning = true;
     Network.SetSendingEnabled(0, true);
     //Fire the level loaded event
     levelLoaded();

 }
 IEnumerator Stall(float seconds){
     yield return new WaitForSeconds(seconds);
 }

The levelLoaded event has a handler on my GameManager script which then runs the SpawnPlayer function here

 private void SpawnPlayer(){
         Debug.Log ("Player Spawned");
         Network.Instantiate(player,new Vector3(0,0,0), Quaternion.identity,0);
     }

The level loads fine but the SpawnPlayer() is never called and I get this error message

 NullReferenceException: Object reference not set to an instance of an object
 NetworkManager.LoadLevel (System.String level, Int32 levelPrefix) (at Assets/Scripts/NetworkManager.cs:82)
 NetworkManager.OnServerInitialized () (at Assets/Scripts/NetworkManager.cs:40)
 UnityEngine.Network:InitializeServer(Int32, Int32, Boolean)
 NetworkManager:StartServer() (at Assets/Scripts/NetworkManager.cs:34)
 NetworkManager:OnClickStartServer() (at Assets/Scripts/NetworkManager.cs:45)
 UnityEngine.EventSystems.EventSystem:Update()

I call DontDestroyOnLoad(this) on my NetworkManager in the Awake() function so its not that the function is being deleted. My guess is since events in c# require a reciever whats happening is that levelLoad is being called before the level is loaded and the GameManager object exists. Although that makes no sense to me since the event is fired well after the loadlevel call is being made.

I should note that my level load method is based off this article. I know they use the dreaded SendMessage instead of calling an event like I did (for what's it worth I tried their SendMessage method and it still didn't work). My JS isn't as up to snuff as it could be so it's possible I've mistranslated something here?

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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Stuck on ConnectingToNameServer 0 Answers

Photon Networking - Synchronization problem 1 Answer

Unity networking custom properties 0 Answers

Photon Networking Child Inconsistencies 0 Answers

Photon View - Player Names/Properties. 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