Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by BerkayDrsn_Legacy · May 21, 2015 at 07:43 PM · unity 5scenephotonrpc

Changing scene while joinin room and RPC buffer in Unity Photon Networking

I have a button to create and join a random room in my main menu. After the client joins (or creates and joins) a random room, i change the scene to game(main) scene in "OnJoinedRoom" function. It works well untill i use RPC call with buffers.

There are 5 spawn points in game scene, and everytime a player joins the room, it "occupys" a spawn point, so noone else can spawn at that point. So i have list of spawn points in my code, and everytime a player joins, it randomly picks a point from that list and "removes" it from the list, and does this by a RPC call so, whoever joins the game after, they remove that point too.

But there is a problem with that RPC's buffer because of the "scene change" thing. As i said, i "join a room" and then "change the scene" when the "OnJoinedRoom" gets called. Because of this, RPC buffers are called just when the player joins the room, and before the scene change. And because the scene hasn't changed yet, it troubles to find the buffered photonview. I throw outs an error, and doesn't update that list.

Can i delay the buffer calls? Or how else should i change my scene while joining a room? What am i doing wrong?

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

Answer by JJNCreator · May 23, 2015 at 02:41 PM

There's an easier way to change your scene while joining a room. Set up a custom room property when creating a room. This property can have any unique name. Then, in the OnJoinedRoom function, call this:

 PhotonNetwork.LoadLevel(PhotonNetwork.room.customProperties["propertyName"].ToString());

What this does is it will load a level as a room, using the value of your custom property as the level name.

How the scene in the lobby is selected is sort on you to figure out, but what I did was I set up an array of strings and an index along with some GUI functions. Something like this:

 GUILayout.BeginHorizontal();
                 if (GUILayout.Button("<", GUILayout.Height(20)))
                 {
                     mapIndex--;
                 }
                 if (mapIndex < 0)
                 {
                     mapIndex = maps.Length - 1;
                 }
                 GUILayout.Label(selectedMap);
                 if (GUILayout.Button(">", GUILayout.Height(20)))
                 {
                     mapIndex++;
                 }
                 if (mapIndex > maps.Length - 1)
                 {
                     mapIndex = 0;
                 }
 
                 selectedMap = maps[mapIndex];

                 GUILayout.EndHorizontal();

When other players join your room, their clients will also be loaded into the same scene.

Hope this helps.

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 ErwinJB · Jan 20, 2017 at 09:56 PM 0
Share

I have a join button so if I set custom properties on room for example a specific hashtable with the scene name when I will press join button automatically change the scene for my game to the room scene ?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

ParticleSystem at Photon Not working! 2 Answers

[Photon] Restart scene rpc doesn't work 1 Answer

Load data from file, if scene changed, fails to load location 0 Answers

Problem with animation RPC in Photon 1 Answer

Sync An Object not Controlled by Players 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