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 question was closed Jul 25, 2012 at 10:35 PM by ExTheSea for the following reason:

In another script there was a line blocking any RPC immediately after the client connects to the game. This way the necessary RPC couldn't pass.

avatar image
1
Question by ExTheSea · Jun 24, 2012 at 01:13 PM · networkrpcmultiplenetworkviewmaps

Help with Network Script. Game with multiple Maps.

Hey guys.

So I try making a script which makes it so that when a new player connects to a server he automatically loads the map currently played on the server.

Here is my script:

 private var Map : String;
 private var lastLevelPrefix = 0;
 
 function Awake ()
 {
     // Network level loading is done in a separate channel.
     DontDestroyOnLoad(this);
     networkView.group = 1;
 }
 
 function OnConnectedToServer() {
 var viewID : NetworkViewID= networkView.viewID;
 networkView.RPC("CallServerSync", RPCMode.Server, viewID);
 }
 
 //Here was the part which makes it so that the server loads the selected map. I deleted it for this question
 
 @RPC
 function LoadLevel (level : String, levelPrefix : int)
 {
     lastLevelPrefix = levelPrefix;
 
         // There is no reason to send any more data over the network on the default channel,
         // because we are about to load the level, thus all those objects will get deleted anyway
         Network.SetSendingEnabled(0, false);    
 
         // We need to stop receiving because first the level must be loaded first.
         // Once the level is loaded, rpc's and other state update attached to objects in the level are allowed to fire
         Network.isMessageQueueRunning = false;
 
         // All network views loaded from a level will get a prefix into their NetworkViewID.
         // This will prevent old updates from clients leaking into a newly created scene.
         Network.SetLevelPrefix(levelPrefix);
         Application.LoadLevel(level);
         yield;
         yield;
 
         // Allow receiving data again
         Network.isMessageQueueRunning = true;
         // Now the level has been loaded and we can start sending out data to clients
         Network.SetSendingEnabled(0, true);
 }
 
 @RPC
 function CallServerSync(viewID : NetworkViewID){
 networkView.RPC("GetServerInfo", viewID.owner,Map);
 }
 
 @RPC
 function GetServerInfo(ServerMap:String){
 Debug.Log("Server got called!");
 Map=ServerMap;
 Network.RemoveRPCsInGroup(0);
 Network.RemoveRPCsInGroup(1);
 networkView.RPC( "LoadLevel", RPCMode.AllBuffered, Map, lastLevelPrefix + 1);
 }
 
 @script RequireComponent(NetworkView)


The script is attached to the Main Camera which handles the menu.

The part of the server works. CallServer Sync gets called but GetServerInfo doesn't. I don't get any errors on the client. The Client just get stuck on the "Starting the game"-Screen.

I really hope someone can help me.

Edited:

I changed the CallServerSync function like Mike said but that didn't solve my problem. Nothing really changed. GetServerInfo still doesn't get called on the client.

Update:

I currently went back to another method where I pass the information through the comment because this way doesn't seem to work like I wanted it to. If some of you still have an idea of how I could get this method working I would be happy to hear it.

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

2 Replies

  • Sort: 
avatar image
0

Answer by whydoidoit · Jun 24, 2012 at 01:58 PM

Your call Server Sync function looks a bit strange - I think it should look like this:

 @RPC
 function CallServerSync(viewID : NetworkViewID){
      networkView.RPC("GetServerInfo", RPCMode.All,Map);
 }

Also - you are aware that networkView.RPC("CallServerSync", RPCMode.Server, viewID); will not happen if you are running that code on the server.

Comment
Add comment · Show 20 · 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 whydoidoit · Jun 24, 2012 at 02:00 PM 0
Share

Actually on further reflection you are doing that ServerSync call every time a client connects but it is talking to all clients - then your GetServerInfo call is also talking to all clients.

You should:

  • issue a call on the server when the client connects passing the networkViewId of the client

  • issue a GetServerInfo call on the single specific client passing the map reference

  • just load the level in GetServerInfo not issue another RPC.

avatar image ExTheSea · Jun 24, 2012 at 02:19 PM 0
Share

In my script I tried to do the exact same thing. When you connect to the server ( so OnConnectedToServer) I call ServerSync and pass the networkView.viewID:

var viewID : NetworkViewID= networkView.viewID;

networkView.RPC("CallServerSync", RPC$$anonymous$$ode.Server, viewID);

Then the server calls GetServerInfo only at the networkview attached to the viewID passed to the CallServerSync function:

var NV: NetworkView = NetworkView.Find(viewID); // Finds the NetworkView with the viewID passed to the function

NV.RPC("GetServerInfo", RPC$$anonymous$$ode.All,$$anonymous$$ap); //Calls only at the certain Networkview

If I screwed something up because I don't quite understood what you want to say then please could you explain it some further.

avatar image whydoidoit · Jun 24, 2012 at 02:48 PM 0
Share

You need to address the call to the connecting player:

  networkView.RPC("GetServerInfo", viewID.owner, $$anonymous$$ap);

This send it to just that player - the RPC$$anonymous$$ode.All is sending it to everyone...

avatar image ExTheSea · Jun 24, 2012 at 02:57 PM 0
Share

So I changed it and edited in my question but that didn't solved the problem that the function doesn't get called.

avatar image whydoidoit · Jun 24, 2012 at 04:16 PM 0
Share

So you are getting the CallServerSync, that object exists on all players and is a scene object with a fixed id?

Show more comments
avatar image
0

Answer by ExTheSea · Jul 15, 2012 at 10:20 PM

So I'm gonna reactivate this question because I tried some stuff as a result of the master server going down.

Now I tried a more simple version:

 function OnConnectedToServer()
 {
 yield;
 yield;
 var ClientID = networkView.viewID;
 transform.networkView.RPC("PlayerConnect", RPCMode.Server, ClientID);
 }
 
 @RPC
 function PlayerConnect(Client : NetworkViewID){
 if(Map1) //is true if Map 1 is played
 networkView.RPC("LoadLevel1", Client.owner);
 if(Map2) //is true if Map 2 is played
 networkView.RPC("LoadLevel2", Client.owner);
 }
 
 @RPC
 function LoadLevel1()
 {
 Application.LoadLevel(1);
 }
 
 @RPC
 function LoadLevel2()
 {
 Application.LoadLevel(2);
 }
 
 function OnNetworkLoadedLevel(){
 LevelLoaded=true;
 }

This is a part of a script attached to the MainCamera which has a NetworkView. Also in the Awake function I put in DontDestroyOnLoad(this).

That doesn't really work unfortunately. As a server I get error messages that the RPC wasn't called because PlayerConnect doesn't exist in a random object in the scene. The object stays the same each time I try but it's always a different one when I change Map/Scene.

The Client can't load the map as a result of that.

I hope someone find the problem in my code. I really do as I get this kind of error everytime I try to pass the map through RPC's.

Every push in the right direction is much appreciated.

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 ExTheSea · Jul 18, 2012 at 09:10 PM 0
Share

Now I get "RPC failed because the script couldn't be loaded. The function is "PlayerConnect"" all of the sudden. Don't know why. I don't have a missing script or an empty one attached to the $$anonymous$$ainCamera.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Can not make RPC calls during Start() 1 Answer

Does the position change need state synchronization? 2 Answers

RPC Player Name and show it above head 0 Answers

AllocateViewID over RPC but the NetworkView doesn't exist 2 Answers

View ID AllocatedID: # not found during lookup. Strange behaviour may occur 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