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 /
This question was closed Dec 01, 2019 at 09:24 PM by gadoy- for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by gadoy- · Dec 01, 2019 at 05:54 PM · 2d gamerandomphotonloadlevelpun

Photon Pun 2, How to have all players using the same random generation than the host's?

Okay, so I am new in Photon, and in Unity. I have followed a few tutorials here and there to build what i have right now. I have managed to create a room, to make another player see the room. When the first player create a game, the program generates a random 2D map with planets of different sizes. The problem is, when the second player joins the room, he generates it's own random map and doesn't use the one of the first player. Here are the two files that I think have an error.

CreateRoom.cs :

 using UnityEngine;
 using Photon.Pun;
 using Photon.Realtime;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 
 public class CreateRoom : MonoBehaviourPunCallbacks
 {
     [SerializeField]
     private Text roomName;
 
     [SerializeField]
     private int maxPlayer = 5;
 
     private RoomOptions roomOptions = new RoomOptions();
 
     public void OnClick_CreatePhotonRoom()
     { 
         if (!PhotonNetwork.IsConnected)
         {
             Debug.Log("You're not connected to the server! Connect to the server before trying to create a room");
             return;
         }
         else
         {
             roomOptions.MaxPlayers = (byte) maxPlayer;
             //roomOptions.EmptyRoomTtl = 15000;
             if(roomName.text != null)
             {
                 PhotonNetwork.CreateRoom(roomName.text, roomOptions, TypedLobby.Default);
             }
             else
             {
                 Debug.LogError("You have to specify a room name before creating a room duh");
             }
         }
     }
     
     public override void OnCreatedRoom()
     {
         Debug.Log("Room " + roomName.text + " successfully created.");
         PhotonNetwork.JoinRoom(roomName.text);
     }
 
     public override void OnCreateRoomFailed(short returnCode, string message)
     {
         Debug.Log("Failed to create the room" + roomName.text + ", cause : " + message.ToString());
     }
 
     public override void OnJoinedRoom()
     {
         Debug.Log("Room " + roomName.text + " successfully joined! :D");
         if(PhotonNetwork.IsMasterClient)
 {
             PhotonNetwork.LoadLevel("InGame");
         }
     }
 
     public override void OnJoinRoomFailed(short returnCode, string message)
     {
         Debug.Log("Failed to join the room" + roomName.text + ", cause : " + message.ToString());
     }
     
 }
 

The second one is a button on an image which when clicked, join the room of the first player :

 using Photon.Pun;
 using Photon.Realtime;
 using UnityEngine;
 using TMPro;
 public class ListingPrefab : MonoBehaviourPunCallbacks
 {
     [SerializeField]
     private TextMeshProUGUI text;
 
     public RoomInfo roomInfo { get; private set; }
 
     public void SetRoomInfo(RoomInfo roomInfo)
     {
         this.roomInfo = roomInfo;
         text.text = roomInfo.Name + " Max players : " + roomInfo.MaxPlayers;
     }
 
     public void OnClick_JoinRoom()
     {
         Debug.Log(roomInfo.Name);
         PhotonNetwork.JoinRoom(roomInfo.Name.ToString());
     }
 
     public override void OnJoinedRoom()
     {
         Debug.Log("We are connected to the room : " + roomInfo.Name);
         PhotonNetwork.LoadLevel("InGame");
     }
 
     public override void OnJoinRoomFailed(short returnCode, string message)
     {
         Debug.Log("Failed entering the room : " + roomInfo.Name + " for cause : " + message);
     }
 }

Thanks for any help :)

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

  • Sort: 
avatar image
0

Answer by gangafinti · Dec 01, 2019 at 06:02 PM

Use a random seed and send it to all the clients, they can then generate the exact same content.

https://docs.unity3d.com/530/Documentation/ScriptReference/Random-seed.html

Comment
Add comment · Show 1 · 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 gadoy- · Dec 01, 2019 at 09:24 PM 0
Share

I just made it through. I thought about a seed but i have get better with algorithms and stuff :)) The thing i have done is I activated the GenerationWorld() $$anonymous$$ethod for all the player who aren't masterClients, Changed all my Instantiate calls by InstantiateSceneObject and then Sync all my planets with everybody. Sorry for having asked something not that difficult :))

Follow this Question

Answers Answers and Comments

158 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

Related Questions

Custom Properties, Unity, Object refence not set to an instance of an object 0 Answers

Callback for DNS entry error using Photon Networking 0 Answers

PUN (Photon Unity Networking) Players Move Other Players 1 Answer

PUN2, other player's prefab not populating in assigned field in unity editor 1 Answer

Photon disconnect after switching from mobile data to WIFI 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