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 Rinktacular · Apr 28, 2018 at 05:00 PM · networkingmultiplayerphotononline game

Unity, PLayFab, and Photon - Players are loading into rooms, can interact with the same objects, but cannot see each other

I am working on a multiplayer game in Unity which is using Playfab and the Authentication and Photon which is hosting the multiplayer. I can successfully get players into the same room and I can load the scene after players 'join' the room, however, when 2 players are in the same room, they can not see each other.

This is my authentication service:

 public class LoginWithCustomID : MonoBehaviour
 {
     private string _playFabPlayerIdCache;
     private bool _isNewAccount;
     private string _playerName;

     // Use this to auth normally for PlayFab
     void Awake()
     {
         PhotonNetwork.autoJoinLobby = false;
         PhotonNetwork.automaticallySyncScene = true;
         DontDestroyOnLoad(gameObject);
         authenticateWithPlayfab();
     }

     private void authenticateWithPlayfab()
     {
         var request = new LoginWithCustomIDRequest
         {
             CustomId = "CustomId123",
             CreateAccount = true,
             InfoRequestParameters = new GetPlayerCombinedInfoRequestParams()
             {
                 GetUserAccountInfo = true,
                 ProfileConstraints = new PlayerProfileViewConstraints()
                 { ShowDisplayName = true }
             }
         };
         PlayFabClientAPI.LoginWithCustomID(request, requestPhotonToken, OnLoginFailure);
     }

     private void requestPhotonToken(LoginResult result)
     {
         PlayerAccountService.loginResult = result;
         _playFabPlayerIdCache = result.PlayFabId;
         _playerName = result.InfoResultPayload.AccountInfo.TitleInfo.DisplayName;
         if (result.NewlyCreated)
         {
             _isNewAccount = true;
             setupNewPlayer(result);
         }

         PlayFabClientAPI.GetPhotonAuthenticationToken(new GetPhotonAuthenticationTokenRequest()
         {
             PhotonApplicationId = "photonId123"
         }, AuthenticateWithPhoton, OnLoginFailure);
     }

     private void setupNewPlayer(LoginResult result)
     {
         PlayFabClientAPI.UpdateUserData(
             new UpdateUserDataRequest()
             {
                 Data = new Dictionary<string, string>()
                 {
                     { "Level", "1" },
                     { "xp", "0" }
                 }
             }, success =>
             {
                 Debug.Log("Set User Data");
             }, failure =>
              {
                  Debug.Log("Failed to set User Data..");
              }
         );
     }

     private void AuthenticateWithPhoton(GetPhotonAuthenticationTokenResult result)
     {
         Debug.Log("Photon token acquired: " + result.PhotonCustomAuthenticationToken);
         var customAuth = new AuthenticationValues { AuthType = CustomAuthenticationType.Custom };
         customAuth.AddAuthParameter("username", _playFabPlayerIdCache);
         customAuth.AddAuthParameter("token", result.PhotonCustomAuthenticationToken);
         PhotonNetwork.AuthValues = customAuth;
         setNextScene();            
     }

     private void setNextScene()
     {
         if(_isNewAccount || _playerName == null)
         {
             SceneManager.LoadSceneAsync("CreatePlayerName", LoadSceneMode.Single);
         }
         else
         {
             SceneManager.LoadSceneAsync("LandingScene", LoadSceneMode.Single);
         }
     }

     private void OnLoginFailure(PlayFabError error)
     {
         Debug.LogWarning("something went wrong in auth login");
         Debug.LogError("Here's some debug info:");
         Debug.LogError(error.GenerateErrorReport());
     }

 }
 }

This all works and a player is logged into PlayFab, as well as Photon I would assume if I got the Photon auth token. This brings me to my landing scene, which is essentially a place for an authenticated user to click a button to join a random room via Photon:

 public static GameManager instance;
 public static GameObject localPlayer;

 private void Awake()
 {
     if (instance != null)
     {
         DestroyImmediate(instance);
         return;
     }
     DontDestroyOnLoad(gameObject);
     instance = this;
     PhotonNetwork.automaticallySyncScene = true;
 }

 // Use this for initialization
 void Start()
 {
     PhotonNetwork.ConnectUsingSettings("A_0.0.1");
 }

 public void JoinGame()
 {
     RoomOptions ro = new RoomOptions();
     ro.MaxPlayers = 4;
     PhotonNetwork.JoinOrCreateRoom("Test Room 2", ro, null);
 }

 public override void OnJoinedRoom()
 {
     Debug.Log("Joined Room!");
     if (PhotonNetwork.isMasterClient)
     {
         PhotonNetwork.LoadLevel("Test_Map1");
     }
 }

 private void OnLevelWasLoaded(int level)
 {
     if (!PhotonNetwork.inRoom)
         return;

     localPlayer = PhotonNetwork.Instantiate(
         "Player",
         new Vector3(0, 1f, 0),
         Quaternion.identity,
         0);
 }

 public void LeaveRoom()
 {
     PhotonNetwork.LeaveRoom();
     SceneManager.LoadScene("LandingScene", LoadSceneMode.Single);
 }




This loads the scene that I named "Test_scene1" successfully and I show within my scene, the room name and number of active players in the room. When I do a run and build, I get a user's playerPrefab to load into the room. When I run the game through unity, I can get a second player to log into the room. The problem is, the players do not see eachother and I can not figure out why that is. I am following the PLayerfab/Photon tutorials on their respective sites, but I can't find anything that I did wrong in either one.

From what I read, it looks like my instantiate method might be wrong but I'm not sure why. Below is my player Prefab showing the components attached to it:

Player image

I apologize for this huge question (and this awful formatting..), I just wanted to provide as much information as I could.

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 Rinktacular · Apr 28, 2018 at 05:13 PM 0
Share

As a side note, the players are both being loaded, but the non-local player(s) prefabs in each instance of the game are "deactivated" which is why I can't see them. However, I am not setting them to be inactive anywhere in my code, which I think would be the underlying problem.

avatar image ChristianSimon · May 03, 2018 at 09:14 AM 0
Share

I currently don't know why the other client's object is not visible. If you run one client in a 'build version' and another client in the Unity Editor, please check in the editor if the other client's game object gets created properly. You can simply do this by taking a look at the scene hierarchy. If the object get created properly, please also check, if it is enabled (game object itself) and visible (renderer component).

If the object is not created properly, you can add two more Debug.Log calls to any script attached to the game object. In this case it would be interesting to know, when the object gets instantiated (add one Debug.Log call to its Awake function) and when the object gets destroyed (add another Debug.Log call to its OnDestroy function). A third Debug.Log call inside the OnLevelWasLoaded function would be interesting as well, just to know, when the other calls happen.

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

164 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 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

Unity networking tutorial? 6 Answers

Best Photon Synchronize settings for smooth online multiplayer 2 Answers

Collision over photon network is not working 1 Answer

Best Solution for Multiplayer Shooting 1 Answer

How to implement server side logic with PHOTON? 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