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 /
  • Help Room /
avatar image
0
Question by DrkProdigy09 · Sep 04, 2016 at 02:14 PM · unity 5photon

Can't get photon to spawn players, or join the same room.

I'm making an agar.io like copy for a project to gain experience with unity.

I'm using Photon to manage networking. I have a NetworkManager script below, that is active in my scene and setup correctly, with player prefab (in resources folder), room name, and spawnpoint. using UnityEngine; using System.Collections;

 public class NetworkManager : MonoBehaviour {
 
     const string VERSION = "1";
     public string roomName = "ffa";
     public string playerPrefabName = "Player";
     public Transform spawnPoint;
 
     void Start () {
         PhotonNetwork.ConnectUsingSettings(VERSION);
         Debug.Log("NetworkManager Started");
     }
 
     void onJoinedLobby() {
         RoomOptions roomOptions = new RoomOptions() { IsVisible = false, maxPlayers = 4 };
         PhotonNetwork.JoinOrCreateRoom(roomName, roomOptions, TypedLobby.Default);
         isConnected();
     }
 
     void onJoinedRoom() {
         PhotonNetwork.Instantiate(playerPrefabName, spawnPoint.position, spawnPoint.rotation, 0);
         isConnected();
     }
 
     void isConnected() {
         if(PhotonNetwork.connected == true) {
             Debug.Log("connected");
         } else {
             Debug.Log("not connected");
         }
     }
 }

Now, my issue seems to be that overall onJoinedLobby, and onJoinedRoom, aren't ever firing, as I don't get my debug messages, while I do get the one from Start(). Another issue is that when I remove my player prefab from the scene like I should, and start my game, it never spawns, of course that is because neither of my functions are ever firing, because my client never seems to join a room/lobby.

Also getting a debug message in chat that I can't seem to find any info on why it's happening from google or docs.

 SwitchToProtocol: Udp PhotonNetwork.connected: False
 UnityEngine.Debug:Log(Object)
 PhotonNetwork:SwitchToProtocol(ConnectionProtocol) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:1172)
 PhotonNetwork:ConnectUsingSettings(String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:1219)
 NetworkManager:Start() (at Assets/Assets/NetworkManager.cs:12)

Any help? First time messing with Photon or really unity anyways. Thanks.

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
Best Answer

Answer by tobiass · Sep 05, 2016 at 09:33 AM

There is no error in your logs. We can't debug your code. Have a look at the ConnectAndJoinRandom.cs. If this also fails, find the PhotonServerSettings file and delete it. The PUN Wizard should pop up and create a new one. Insert your AppId from the Dashboard.

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 DrkProdigy09 · Sep 05, 2016 at 01:16 PM 0
Share

I reset the PUN settings and actually created an entire new project twice, didn't fix it.

What seemed to be the issue was simply how I was handling the status. I don't really have the best internet so, sometimes things take a bit to process, which was what was happening. It was starting to connect but didn't finalize it. Here is the script I finally got to work (at midnight :P) using UnityEngine; using System.Collections;

 public class NewNetworkScript : $$anonymous$$onoBehaviour {
 
     public string status;
     public string roomName;
     public string playerPrefabName = "StarterBall";
     public Transform spawnPoint;
 
     private int counter = 1;
 
     void Start () {
         Connect();
         InvokeRepeating("UpdateStatus", 2, 1);
     }
 
     void Connect() {
         PhotonNetwork.ConnectUsingSettings("v001");
     }
     
     void UpdateStatus() {
         status = PhotonNetwork.connectionStateDetailed.ToString();
 
         if(status == "JoinedLobby") {
             RoomOptions roomOptions = new RoomOptions();
             PhotonNetwork.JoinOrCreateRoom(roomName, roomOptions, TypedLobby.Default);
         }
         if(status == "Joined" && counter == 1) {
             onJoinedRoom();
             counter = 2;
         }
     }
 
     void onJoinedRoom() {
         PhotonNetwork.Instantiate(playerPrefabName, spawnPoint.position, spawnPoint.rotation, 0);
     }
 
 
 }
 
avatar image DrkProdigy09 · Sep 05, 2016 at 02:00 PM 0
Share

Although, I do have a question regarding PhotonView.is$$anonymous$$ine and meshes (colors on my spheres in a agar.io like game)

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class ColorChanger : $$anonymous$$onoBehaviour {
 
     public List<$$anonymous$$aterial> $$anonymous$$ats = new List<$$anonymous$$aterial>();
     public PhotonView pv;
 
     void Start() {
         pv = PhotonView.Get(this);
     }
 
     void Awake() {
         if(pv.is$$anonymous$$ine) {
             GetComponent<Renderer>().material = $$anonymous$$ats[Random.Range(0, $$anonymous$$ats.Count)];
         }
     }
 }

Seems to kinda work. For example I'll spawn in on the editor as red, then I'll open the app on my pc and it'll spawn as black, which is what I see on the editor. but then in my app I see my original as black ins$$anonymous$$d of red, and then the new app one is green.

Any help? Sorry if I'm confusing. @tobiass

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

109 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 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 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 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 avatar image

Related Questions

Photon ccu question 1 Answer

Photon Multiplayer UI Issue 1 Answer

Unity login system without Photon Custom Auth 0 Answers

how do you enable/disable a camera from the new unity 5 fpscontroller camera for a multiplayer game using PUN 1 Answer

PhotonView script PlayerPrefab Transform problem 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