Quantcast
Channel: Questions in topic: "online game"
Viewing all articles
Browse latest Browse all 36

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

$
0
0
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() { { "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][1] I apologize for this huge question (and this awful formatting..), I just wanted to provide as much information as I could. [1]: https://i.stack.imgur.com/0tmg7.png

Viewing all articles
Browse latest Browse all 36

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>