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 /
avatar image
0
Question by smallkhb · Mar 23, 2014 at 02:47 AM · instantiatemultiplayernetworknetworkviewroom

How to implement a Room Mode Multiplayer Game code structure.

I am trying to seperate players into different room by setting them a difenent networView.group id just like this:

     function OnPlayerConnected(p:NetworkPlayer) {
       var n:int = Network.connections.length;
       if ((n%2) == 1) { // simply divide into 2 room(room id is 3 and 4).
         Network.SetReceivingEnabled(p, 4, false);
         Network.SetSendingEnabled(p, 4, false);
         networkView.RPC("SetGroup", player, 3);
         // the odd player will be in room 3 and not receive room 4's message
       } else {
         Network.SetReceivingEnabled(p, 3, false);
         Network.SetSendingEnabled(p, 3, false);
         networkView.RPC("SetGroup", player, 4);
         // the even player will be in room 4 and not receive room 3's message
       }
     }
     @RPC
     function SetGroup(group:int) {
       myRoomGroup = group;
     }
     function OnGUI() { // client
       if (Network.isClient) {
         if (GUILayout.Button("spawn")) {
           Network.Instantiate(prefabTest, Vector3.zero, Quaternion.identity, myRoomGroup);
         }
       }
     }

Ok, that is the main code above, and the situation is like this: There are Server, Client1, Client2, Client3 for this test.

     Server.start();
     Client1.connect(); // in room 3
     Client2.connect(); // in room 4
     Client1.click("spawn");
       // PrefabTest.spawned at Client1 and at Server.
       // PrefabTest doing not instantiated in Client2 is what I want as I just want
       // seperate Client1 and Client2 to different room. And there meesage won't send
       // to each or received from, so now it runs well.
     Client2.click("spawn");
       // PrefabTest.spawned at Client2 and at Server.
       // So this is also right for my purpose.
     Client3.connect(); // in room 3
       // Client1.prefabTest is synchronized to Client3(yes, i want it);
       // Client2.prefabTest is also synchronized to Client3(oh no...);
 

The problem is that the Client2.prefabTest should not be instantiated to Client3 as that is not I want. And the reason is that the buffered-RPC(Network.Instaiated) is invoked when a player connected and before Server.OnPlayerOnnected is called, so my code is a little later than the auto-synchronization, so the problem occurred.

As trying useing the NetworkView with a same group id insteading of the Network.Instantiate for synchonizing GameObject, the Synchronization is always lanuched from the server to client since the networkView.owner(0) is alway the server.

I have try thinking of many way to implement a room mode for multiplayer game by using Network System, but I think I am going in a wrong way (:3|L)_. So what is the correct way to implement Room mode using unity's Network System? Many thank for any replay :) .

by smallkhb 2014-03-23

Comment
Add comment · Show 1
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 smallkhb · Mar 23, 2014 at 03:57 AM 0
Share

I am sorry for posted the same problem in another submit. I will delete it if it is published.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by fholm · Mar 27, 2014 at 05:15 AM

The correct answer is sadly that networkgroups are not intended for spitting a game like this, and this doesn't work properly (as you have noticed), and there is no real way around this with the default unity networking.

Comment
Add comment · 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

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

21 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

Related Questions

How can I spawn a GameObject on all players in my multiplayer game? 0 Answers

Players Not Showing 0 Answers

Player 2 not spawning 1 Answer

Network.Instantiate instantiazing 2 prefabs 1 Answer

Multiplayer Projectile Instantiation 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