hey! so, I dont think no one is going to answer, but the room list updating does not work correctly for me. lets say player 1 creates a room. now, when player 2 looks at the rooms list, player one's room is not there. but for some reason, when player 2 creates a new room and then leaves it, player one's room is now visible on the room list. anu idea how to fix it?
A system containing many bugs. You make it look like everything is fine. When you get Build, if you open 2 rooms at the same time, only 1 will be visible. And there is another problem: When I open the project I built once and set up a room, it appears in the editor, but when I open the project I built as a 3rd file, no room appears. It's a ridiculous system and you pass without fixing them.
the video is more than one year old! that time it worked properly, even we created a game with for an american publisher but now as the PHOTON has update it systems methods etc... it's possible that we are going in wrong way and we shouldn't use this way anymore by the way thanks for the comment🙏🏻💙
@@budgames thanks. I have a question about Photon. I want to make a simple football game, but the ball does not move on the person setting the room. While other players can easily see the movement of the ball, the host computer, the MasterClient, does not see the movement of the ball. What do I need to change in the code for this? The ball object has "Photon View, Photon Transform View and Photon Rigidbody View" components. Code: using Photon.Pun; using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; public class PlayerController : MonoBehaviour { [SerializeField] float mouseSensitivity, sprintSpeed, walkSpeed, jumpForce, smoothTime; [SerializeField] GameObject cameraHolder; float verticalLookRotation; bool grounded; Vector3 smoothMoveVelocity; Vector3 moveAmount; Rigidbody rb; PhotonView pv; private void Awake() { rb = GetComponent(); pv = GetComponent(); } private void Start() { if (!pv.IsMine) { Destroy(GetComponentInChildren().gameObject); Destroy(rb); } } private void Update() { if (!pv.IsMine) return; PlayerLook(); PlayerMove(); PlayerJump(); } private void PlayerLook() { transform.Rotate(Vector3.up * Input.GetAxisRaw("Mouse X") * mouseSensitivity); verticalLookRotation += Input.GetAxisRaw("Mouse Y") * mouseSensitivity; verticalLookRotation = Mathf.Clamp(verticalLookRotation, -90f, 90f); cameraHolder.transform.localEulerAngles = Vector3.left * verticalLookRotation; } void PlayerMove() { Vector3 moveDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized; moveAmount = Vector3.SmoothDamp(moveAmount, moveDir * (Input.GetKey(KeyCode.LeftShift) ? sprintSpeed : walkSpeed), ref smoothMoveVelocity, smoothTime); } void PlayerJump() { if (Input.GetKeyDown(KeyCode.Space) && grounded) { rb.AddForce(transform.up * jumpForce); } } public void SetGroundState(bool _grounded) { grounded = _grounded; } private void FixedUpdate() { if (!pv.IsMine) return; rb.MovePosition(rb.position + transform.TransformDirection(moveAmount) * Time.fixedDeltaTime); } private void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag("Ball")) { Rigidbody ballRb = collision.gameObject.GetComponent(); if (ballRb != null) { ballRb.AddForce(transform.forward * 1f, ForceMode.Impulse); } } } }
@@budgames thanks. I have a question about Photon. I want to make a simple football game, but the ball does not move on the person setting the room. While other players can easily see the movement of the ball, the host computer, the MasterClient, does not see the movement of the ball. What do I need to change in the code for this? The ball object has "Photon View, Photon Transform View and Photon Rigidbody View" components.
If you still are finding the answer it could be due to the following, I´ll give u the example with the script just to make me undertand public class Room : MonoBehaviour { public Text Name; public void JoinRoom() { GameObject.Find("PART1").GetComponent().JoinRoomList(Name.text); } } PART1: It means in that place must to be the game object´s name or the empty game object that contains the script that let you join to a room or create a room. PART2: It means in that place must to be the script´s name that let you join to a room or create a room. It works to me, if it doesn´t to you just let me know.
my error is when the players enter in same time all work right .. but if the room created and players inter the room , the last one who enter the game see all players but other players not see him ,, and also any one enter see all who enter before him but no one see him ,, last one enter game (join room ) see all who enter before but no one see him ??? how i can solve this ?
hi bro thanks but I have this error while creating room CreateRoom failed. Client is on MasterServer (must be Master Server for matchmaking)but not ready for operations (State: PeerCreated). Wait for callback: OnJoinedLobby or onCoonectedToMaster
To refresh the room list in Photon Unity, you can use the PhotonNetwork.GetRoomList() method again. This will fetch an updated list of rooms from the Photon server. Here's an example of how to refresh the room list: csharp Copy code public void RefreshRoomList() { PhotonNetwork.GetRoomList(); } In this example, we're calling the PhotonNetwork.GetRoomList() method to fetch an updated list of rooms. You can call this method in response to a button click or any other user action that you want to use to trigger a refresh of the room list. Note that calling PhotonNetwork.GetRoomList() too frequently can cause performance issues, so you may want to implement some throttling or caching to avoid overloading the server. Additionally, you should only call this method if you're connected to the Photon Cloud or a self-hosted Photon server, and you should handle any errors that may occur if the connection is lost or the server is unavailable. =================== if it doesn't work : If the PhotonNetwork.GetRoomList() method is not refreshing the room list, there could be a few reasons why this is happening. Here are some things you can check: Make sure you're connected to the Photon Cloud or a self-hosted Photon server. You can use PhotonNetwork.connected to check if you're connected. If you're not connected, you should call PhotonNetwork.ConnectUsingSettings() or PhotonNetwork.ConnectToMaster() to establish a connection before calling PhotonNetwork.GetRoomList(). Make sure you're calling PhotonNetwork.GetRoomList() in the correct place in your code. You should call this method after you've established a connection to the Photon server, and you should wait for the OnReceivedRoomListUpdate() callback to be called before you try to access the room list. You can use the PhotonNetwork.insideLobby property to check if you're in a lobby before calling PhotonNetwork.GetRoomList(). Here's an example of how to call PhotonNetwork.GetRoomList() correctly: CSharp Copy code public void RefreshRoomList() { if (PhotonNetwork.connectedAndReady && PhotonNetwork.insideLobby) { PhotonNetwork.GetRoomList(); } } Make sure you're implementing the OnReceivedRoomListUpdate() callback. This method is called when the room list is updated, and it should be used to update your UI or perform any other actions that depend on the room list. Here's an example of how to implement this callback: csharp Copy code public override void OnReceivedRoomListUpdate() { // Update your UI or perform other actions here } By implementing this callback, you can ensure that your UI is updated with the latest room list whenever it changes. If you've checked these things and you're still having issues with refreshing the room list, you may want to check the Photon Unity documentation or forums for additional troubleshooting tips.
Thanks man😄! I found out it was “bugging” because I had the loading thing in a different scene. I made it an image obj and made it disappear when i connected to the lobby.
you should set a new custom property and add it to the room options actually its a bit hard to understand... see this post to understand better : forum.photonengine.com/discussion/17860/rooms-with-password we will talk about it in one of our videos in channel in future for sure
You have very cool videos. Could you record a video? How to properly exit the GamePlay if I am a master or a client. Is there any script? Because simply if I make public void GoToSceneByName(string sceneName) { SceneManager.LoadScene(sceneName); } then there are problems with creating a new room
Load new scene when a new room is joined don't use unity scene manager it causes issues. Use this................................... public override void OnJoinedRoom() { print($" Joined Room : {PhotonNetwork.CurrentRoom.Name} "); //Use this instead of scene manager.loadscene otherwise you will encoutner some issues PhotonNetwork.LoadLevel("Game"); }
Hello, I dont get the update when a room is create, do you know why? To create room i do : private void Start() { PhotonNetwork.ConnectUsingSettings(); Debug.Log("Try connecting to server ..."); } public override void OnConnectedToMaster() { Debug.Log("Connected to server !"); base.OnConnectedToMaster(); } public void CreateRoom() { Debug.Log("Creating a room !"); RoomOptions roomOptions = new RoomOptions(); roomOptions.MaxPlayers = 2; roomOptions.IsVisible = true; roomOptions.IsOpen = true; PhotonNetwork.CreateRoom(inputCreateRoom.text, roomOptions, TypedLobby.Default); } public override void OnJoinedRoom() { base.OnJoinedRoom(); PhotonNetwork.LoadLevel("PassThroughValidation"); } public override void OnRoomListUpdate(List roomList) { Debug.Log("chb ROOM UPDATE"); // Never Happen }
Hi . You probably missed something To get a list of rooms in Photon Unity, you can use the PhotonNetwork.GetRoomList() method. This method returns an array of RoomInfo objects that represent the available rooms in the Photon network. Here's an example of how to use it in a Unity script: using UnityEngine; using Photon.Pun; public class RoomList : MonoBehaviourPunCallbacks { void Start() { PhotonNetwork.GetRoomList(); } public override void OnRoomListUpdate(List roomList) { foreach (RoomInfo room in roomList) { Debug.Log(room.Name + " " + room.PlayerCount + "/" + room.MaxPlayers); } } } In this example, the OnRoomListUpdate method is a callback that is called when the room list is updated. The method loops through the list of rooms and logs the name, player count, and max player count of each room. Note that you must have a Photon account and be connected to the Photon network to use this method. Good Luck :).
Hi, I have 2 problems the first one when i create 2 room with diffrent names its show me only the second room that i created the second one its when the player1 in the room and another player enter to this scene its not show any room in the list
hey! so, I dont think no one is going to answer, but the room list updating does not work correctly for me. lets say player 1 creates a room. now, when player 2 looks at the rooms list, player one's room is not there.
but for some reason, when player 2 creates a new room and then leaves it, player one's room is now visible on the room list. anu idea how to fix it?
Thank you so much. You just save my day.
thanks, very helpful tutorial
You're welcome :)
Hey i am having a problem where the list does not update you can only join with the join inputfield and theres no errors in the console
A system containing many bugs. You make it look like everything is fine. When you get Build, if you open 2 rooms at the same time, only 1 will be visible. And there is another problem: When I open the project I built once and set up a room, it appears in the editor, but when I open the project I built as a 3rd file, no room appears. It's a ridiculous system and you pass without fixing them.
the video is more than one year old!
that time it worked properly, even we created a game with for an american publisher
but now as the PHOTON has update it systems methods etc...
it's possible that we are going in wrong way and we shouldn't use this way anymore
by the way thanks for the comment🙏🏻💙
What you say is true, PHOTON is always updated, but videos from 3 years ago still work. Still, I tried some of them and they worked fine. Good work
@@budgames thanks. I have a question about Photon. I want to make a simple football game, but the ball does not move on the person setting the room. While other players can easily see the movement of the ball, the host computer, the MasterClient, does not see the movement of the ball. What do I need to change in the code for this? The ball object has "Photon View, Photon Transform View and Photon Rigidbody View" components.
Code:
using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
[SerializeField] float mouseSensitivity, sprintSpeed, walkSpeed, jumpForce, smoothTime;
[SerializeField] GameObject cameraHolder;
float verticalLookRotation;
bool grounded;
Vector3 smoothMoveVelocity;
Vector3 moveAmount;
Rigidbody rb;
PhotonView pv;
private void Awake()
{
rb = GetComponent();
pv = GetComponent();
}
private void Start()
{
if (!pv.IsMine)
{
Destroy(GetComponentInChildren().gameObject);
Destroy(rb);
}
}
private void Update()
{
if (!pv.IsMine)
return;
PlayerLook();
PlayerMove();
PlayerJump();
}
private void PlayerLook()
{
transform.Rotate(Vector3.up * Input.GetAxisRaw("Mouse X") * mouseSensitivity);
verticalLookRotation += Input.GetAxisRaw("Mouse Y") * mouseSensitivity;
verticalLookRotation = Mathf.Clamp(verticalLookRotation, -90f, 90f);
cameraHolder.transform.localEulerAngles = Vector3.left * verticalLookRotation;
}
void PlayerMove()
{
Vector3 moveDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
moveAmount = Vector3.SmoothDamp(moveAmount, moveDir * (Input.GetKey(KeyCode.LeftShift) ? sprintSpeed : walkSpeed), ref smoothMoveVelocity, smoothTime);
}
void PlayerJump()
{
if (Input.GetKeyDown(KeyCode.Space) && grounded)
{
rb.AddForce(transform.up * jumpForce);
}
}
public void SetGroundState(bool _grounded)
{
grounded = _grounded;
}
private void FixedUpdate()
{
if (!pv.IsMine)
return;
rb.MovePosition(rb.position + transform.TransformDirection(moveAmount) * Time.fixedDeltaTime);
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Ball"))
{
Rigidbody ballRb = collision.gameObject.GetComponent();
if (ballRb != null)
{
ballRb.AddForce(transform.forward * 1f, ForceMode.Impulse);
}
}
}
}
@@budgames thanks. I have a question about Photon. I want to make a simple football game, but the ball does not move on the person setting the room. While other players can easily see the movement of the ball, the host computer, the MasterClient, does not see the movement of the ball. What do I need to change in the code for this? The ball object has "Photon View, Photon Transform View and Photon Rigidbody View" components.
Code:
using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
[SerializeField] float mouseSensitivity, sprintSpeed, walkSpeed, jumpForce, smoothTime;
[SerializeField] GameObject cameraHolder;
float verticalLookRotation;
bool grounded;
Vector3 smoothMoveVelocity;
Vector3 moveAmount;
Rigidbody rb;
PhotonView pv;
private void Awake()
{
rb = GetComponent();
pv = GetComponent();
}
private void Start()
{
if (!pv.IsMine)
{
Destroy(GetComponentInChildren().gameObject);
Destroy(rb);
}
}
private void Update()
{
if (!pv.IsMine)
return;
PlayerLook();
PlayerMove();
PlayerJump();
}
private void PlayerLook()
{
transform.Rotate(Vector3.up * Input.GetAxisRaw("Mouse X") * mouseSensitivity);
verticalLookRotation += Input.GetAxisRaw("Mouse Y") * mouseSensitivity;
verticalLookRotation = Mathf.Clamp(verticalLookRotation, -90f, 90f);
cameraHolder.transform.localEulerAngles = Vector3.left * verticalLookRotation;
}
void PlayerMove()
{
Vector3 moveDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
moveAmount = Vector3.SmoothDamp(moveAmount, moveDir * (Input.GetKey(KeyCode.LeftShift) ? sprintSpeed : walkSpeed), ref smoothMoveVelocity, smoothTime);
}
void PlayerJump()
{
if (Input.GetKeyDown(KeyCode.Space) && grounded)
{
rb.AddForce(transform.up * jumpForce);
}
}
public void SetGroundState(bool _grounded)
{
grounded = _grounded;
}
private void FixedUpdate()
{
if (!pv.IsMine)
return;
rb.MovePosition(rb.position + transform.TransformDirection(moveAmount) * Time.fixedDeltaTime);
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Ball"))
{
Rigidbody ballRb = collision.gameObject.GetComponent();
if (ballRb != null)
{
ballRb.AddForce(transform.forward * 1f, ForceMode.Impulse);
}
}
}
}
thanks but I have a error:
NullReferenceException: Object reference not set to an instance of an object
Room.JoinRoom () (at Assets/Room.cs:14)
You did not give something for something bro (when you don't feel like answering comments...)
If you still are finding the answer it could be due to the following, I´ll give u the example with the script just to make me undertand
public class Room : MonoBehaviour
{
public Text Name;
public void JoinRoom()
{
GameObject.Find("PART1").GetComponent().JoinRoomList(Name.text);
}
}
PART1: It means in that place must to be the game object´s name or the empty game object that contains the script that let you join to a room or create a room.
PART2: It means in that place must to be the script´s name that let you join to a room or create a room.
It works to me, if it doesn´t to you just let me know.
same
my error is when the players enter in same time all work right .. but if the room created and players inter the room , the last one who enter the game see all players but other players not see him ,, and also any one enter see all who enter before him but no one see him ,, last one enter game (join room ) see all who enter before but no one see him ??? how i can solve this ?
hi bro thanks
but I have this error while creating room
CreateRoom failed. Client is on MasterServer (must be Master Server for matchmaking)but not ready for operations (State: PeerCreated). Wait for callback: OnJoinedLobby or onCoonectedToMaster
you need to run this from the loading page
hi! how do you refresh the room list? I did your tut, very useful btw, but when a new player joins, they can't see the rooms made before he joined
To refresh the room list in Photon Unity, you can use the PhotonNetwork.GetRoomList() method again. This will fetch an updated list of rooms from the Photon server.
Here's an example of how to refresh the room list:
csharp
Copy code
public void RefreshRoomList()
{
PhotonNetwork.GetRoomList();
}
In this example, we're calling the PhotonNetwork.GetRoomList() method to fetch an updated list of rooms. You can call this method in response to a button click or any other user action that you want to use to trigger a refresh of the room list.
Note that calling PhotonNetwork.GetRoomList() too frequently can cause performance issues, so you may want to implement some throttling or caching to avoid overloading the server. Additionally, you should only call this method if you're connected to the Photon Cloud or a self-hosted Photon server, and you should handle any errors that may occur if the connection is lost or the server is unavailable.
=================== if it doesn't work :
If the PhotonNetwork.GetRoomList() method is not refreshing the room list, there could be a few reasons why this is happening. Here are some things you can check:
Make sure you're connected to the Photon Cloud or a self-hosted Photon server. You can use PhotonNetwork.connected to check if you're connected. If you're not connected, you should call PhotonNetwork.ConnectUsingSettings() or PhotonNetwork.ConnectToMaster() to establish a connection before calling PhotonNetwork.GetRoomList().
Make sure you're calling PhotonNetwork.GetRoomList() in the correct place in your code. You should call this method after you've established a connection to the Photon server, and you should wait for the OnReceivedRoomListUpdate() callback to be called before you try to access the room list. You can use the PhotonNetwork.insideLobby property to check if you're in a lobby before calling PhotonNetwork.GetRoomList().
Here's an example of how to call PhotonNetwork.GetRoomList() correctly:
CSharp
Copy code
public void RefreshRoomList()
{
if (PhotonNetwork.connectedAndReady && PhotonNetwork.insideLobby)
{
PhotonNetwork.GetRoomList();
}
}
Make sure you're implementing the OnReceivedRoomListUpdate() callback. This method is called when the room list is updated, and it should be used to update your UI or perform any other actions that depend on the room list. Here's an example of how to implement this callback:
csharp
Copy code
public override void OnReceivedRoomListUpdate()
{
// Update your UI or perform other actions here
}
By implementing this callback, you can ensure that your UI is updated with the latest room list whenever it changes.
If you've checked these things and you're still having issues with refreshing the room list, you may want to check the Photon Unity documentation or forums for additional troubleshooting tips.
Thanks man😄! I found out it was “bugging” because I had the loading thing in a different scene. I made it an image obj and made it disappear when i connected to the lobby.
Glad to hear this :) . Good Luck in your projects
Thanks m8
@@budgames The GetRoomList() Function does not work anymore 😢
how to lock the rooms ?
I mean how to set password
you should set a new custom property and add it to the room options
actually its a bit hard to understand... see this post to understand better : forum.photonengine.com/discussion/17860/rooms-with-password
we will talk about it in one of our videos in channel in future for sure
Hwy how can i make where if player press joinorcteatrandom server it send players to a level
the platforms are literally changed, you must search for a newer video for sure
@@budgames I am using same version as your, any help will be appropriate able
You have very cool videos. Could you record a video? How to properly exit the GamePlay if I am a master or a client. Is there any script? Because simply if I make public void GoToSceneByName(string sceneName)
{
SceneManager.LoadScene(sceneName);
} then there are problems with creating a new room
Load new scene when a new room is joined don't use unity scene manager it causes issues. Use this...................................
public override void OnJoinedRoom()
{
print($" Joined Room : {PhotonNetwork.CurrentRoom.Name} ");
//Use this instead of scene manager.loadscene otherwise you will encoutner some issues
PhotonNetwork.LoadLevel("Game");
}
Thank you!
You're welcome! :).
3:23
İts never show rooms att all just i can create and join but rooms not showing
hi . its simple :
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
public class RoomListManager : MonoBehaviourPunCallbacks, ILobbyCallbacks
{
private void Start()
{
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
PhotonNetwork.JoinLobby();
}
public override void OnRoomListUpdate(List roomList)
{
Debug.Log("Room list updated!");
foreach (RoomInfo room in roomList)
{
Debug.Log("Room Name: " + room.Name + " Players: " + room.PlayerCount + "/" + room.MaxPlayers);
}
}
}
GoodLuck :)
if i create two rooms the second room replaces the first one
room names should be different, otherwise it will be messy a bit😬
Cool. Can i have the asset
you can buy and download sprites from this link : (Asset Store)
assetstore.unity.com/packages/2d/gui/gui-pro-kit-casual-game-176695
@@budgames thankss
Hello, I dont get the update when a room is create, do you know why?
To create room i do :
private void Start()
{
PhotonNetwork.ConnectUsingSettings();
Debug.Log("Try connecting to server ...");
}
public override void OnConnectedToMaster()
{
Debug.Log("Connected to server !");
base.OnConnectedToMaster();
}
public void CreateRoom()
{
Debug.Log("Creating a room !");
RoomOptions roomOptions = new RoomOptions();
roomOptions.MaxPlayers = 2;
roomOptions.IsVisible = true;
roomOptions.IsOpen = true;
PhotonNetwork.CreateRoom(inputCreateRoom.text, roomOptions, TypedLobby.Default);
}
public override void OnJoinedRoom()
{
base.OnJoinedRoom();
PhotonNetwork.LoadLevel("PassThroughValidation");
}
public override void OnRoomListUpdate(List roomList)
{
Debug.Log("chb ROOM UPDATE"); // Never Happen
}
Hi, it's simple:
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
public class RoomListManager : MonoBehaviourPunCallbacks, ILobbyCallbacks
{
private void Start()
{
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
PhotonNetwork.JoinLobby();
}
public override void OnRoomListUpdate(List roomList)
{
Debug.Log("Room list updated!");
foreach (RoomInfo room in roomList)
{
Debug.Log("Room Name: " + room.Name + " Players: " + room.PlayerCount + "/" + room.MaxPlayers);
}
}
}
GoodLuck
Nice❤
I cant list rooms help me pls
Hi . You probably missed something
To get a list of rooms in Photon Unity, you can use the PhotonNetwork.GetRoomList() method. This method returns an array of RoomInfo objects that represent the available rooms in the Photon network.
Here's an example of how to use it in a Unity script:
using UnityEngine;
using Photon.Pun;
public class RoomList : MonoBehaviourPunCallbacks
{
void Start()
{
PhotonNetwork.GetRoomList();
}
public override void OnRoomListUpdate(List roomList)
{
foreach (RoomInfo room in roomList)
{
Debug.Log(room.Name + " " + room.PlayerCount + "/" + room.MaxPlayers);
}
}
}
In this example, the OnRoomListUpdate method is a callback that is called when the room list is updated. The method loops through the list of rooms and logs the name, player count, and max player count of each room.
Note that you must have a Photon account and be connected to the Photon network to use this method.
Good Luck :).
Hi, I have 2 problems
the first one when i create 2 room with diffrent names its show me only the second room that i created
the second one its when the player1 in the room and another player enter to this scene its not show any room in the list
thanks but I have a error:
NullReferenceException: Object reference not set to an instance of an object
Room.JoinRoom () (at Assets/Room.cs:13)
what you've written in that line?
@@budgames I actually fixed it, i cant remember what i did but i fixed it
@@Kingthere 😂❤ prefect, don't touch it then