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 cj31387 · Jan 05, 2014 at 10:48 PM · networkingmultiplayerphotonspawn

Photon - Loads a level but doesn't spawn player.

I added a command to my game to switch levels (/level 0-2). It loads the level but it gets stuck on joining and the player doesn't spawn for some reason, and I don't know why. It should be re-instantiating the player OnJoinedRoom(). Here is my code.


 Chat.cs
 [RPC]
     void ApplyGlobalChatText(string name, string msg)
     {
         ChatEntry entry = new ChatEntry();
         entry.name = name;
         entry.text = msg;
         if (entry.text.Contains("/level 0"))
         {
             PhotonNetwork.isMessageQueueRunning = true;
             PhotonNetwork.LoadLevel(0);
             
         }
         if (entry.text.Contains("/level 1"))
         {
             PhotonNetwork.isMessageQueueRunning = true;
             PhotonNetwork.LoadLevel(1);
             
         }
         if (entry.text.Contains("/level 2"))
         {
             PhotonNetwork.isMessageQueueRunning = true;
             PhotonNetwork.LoadLevel(2);
             
         }
         chatEntries.Add(entry);
 
         if (chatEntries.Count > 4)
         {
             chatEntries.RemoveAt(0);
         }
 
         scrollPosition.y = 1000000;
         //555 This was erasing chat for everyone
         //inputField = "";
 
         
     }

 MPManger.cs 
 
 using UnityEngine;
 using System.Collections;
 
 public class MPManager : Photon.MonoBehaviour
 {
 
     public GameObject[] spawnPoints;
 
 
     // Use this for initialization
     void Start()
     {
         spawnPoints = GameObject.FindGameObjectsWithTag("SpawnPoint");
         PhotonNetwork.ConnectUsingSettings("0.4");
 
         //int spawnRand = Random.Range(0, spawnPoints.Length);
     }
 
     void OnGUI()
     {
         GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
     }
 
     void OnJoinedLobby()
     {
         PhotonNetwork.JoinRandomRoom();
     }
 
     void OnPhotonRandomJoinFailed()
     {
         PhotonNetwork.CreateRoom("Aftermath - AW");
     }
 
     void OnJoinedRoom()
     {
         //555 Stupid inconsistency with random.range, it starts at 1 instead of 0.
         GameObject myPlayer = PhotonNetwork.Instantiate("Player_MP", spawnPoints[Random.Range(1, spawnPoints.Length)].transform.position, spawnPoints[Random.Range(1, spawnPoints.Length)].transform.rotation, 0);
         string playerNumber = Random.Range(1, 1000).ToString();
         myPlayer.GetComponent<PhotonView>().owner.name = playerNumber;
         myPlayer.name = "Player" + playerNumber;
     }
 
     void OnDisconnectedFromPhoton()
     {
         //PhotonNetwork.DestroyPlayerObjects(photonView.ownerId);
         //print(photonView.ownerId + " objects destroyed from server");
     }
 }



What am I doing wrong? The spawnpoints are in each level also. Actually I just thought of something. Is start for the spawnpoints getting called when I switch levels? Maybe that is actually the problem. But I'm not getting a null ref. The mpmanger is on a gameobject prefab that is in every level.

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 HuskyPanda213 · Jan 06, 2014 at 04:43 AM 0
Share

Your code has 2, onjoinedroom, one, making you connect to a random room?, and two creating the player. Use only the player one.

avatar image cj31387 · Jan 06, 2014 at 04:54 AM 0
Share

I did it the way photon shows to do it, if I disable the random room the first room never gets created. Also can you be more specific? there is OnPhotonRandomJoinFailed(),OnJoinedRoom(), OnJoinedLobby() .

avatar image HuskyPanda213 · Jan 10, 2014 at 06:26 AM 0
Share

When does onjoinedlobby get called.

avatar image cj31387 · Jan 10, 2014 at 06:40 AM 0
Share

Photon works by joining a lobby first, then a client creates a room(game) so its before room.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Shkarface-Noori · Jan 10, 2014 at 07:14 AM

Photon uses prefab cache to cache prefabs for faster performance...you have to cache your prefab in the resources folder with the exact name used in PhotonNetwork.Instantiate

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 cj31387 · Jan 10, 2014 at 08:17 AM 0
Share

Yeah that is what this line is doing. Loading from my resources folder, but It doesn't re-spawn, reinstantiate (give a person the prefab to control) the player when I do a level change. I know this line is working because Im able to join a room, with a player. But the problem is when I use my switch level command it doesn't respawn the player into the new loaded level.


 GameObject myPlayer = PhotonNetwork.Instantiate("Player_$$anonymous$$P", spawnPoints[Random.Range(1, spawnPoints.Length)].transform.position, spawnPoints[Random.Range(1, spawnPoints.Length)].transform.rotation, 0);
avatar image CodyMoores · Mar 10, 2014 at 11:31 PM 0
Share

Did you attach PhotonView on to the playerprefab?

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

Spawn players in unique places (Photon networking) Object sync problem for entering players. 0 Answers

Unity networking tutorial? 6 Answers

MLAPI spawn player prefab 2 Answers

Photon Unity Network - Refresh/Tickrate 2 Answers

Unity Photon syncing objects 0 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