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 /
  • Help Room /
avatar image
0
Question by Whitby93 · Oct 07, 2016 at 10:57 PM · networkingnetworkhudmanager

Creating a custom NetworkManagerHUD

I started out by debugging the stock JS example of the network connection script then tried adding some more functions. I believe what I am failing to achieve is setting the "Client Ready" state of the players. I would like this to be set automatically when possible, if possible. It appears to be capable of creating and joining a server using multiple clients based upon the console logs, although no players get spawned in. Console when creating a server:

 MatchMakingClient Create :https://eu1-mm.unet.unity3d.com/json/reply/CreateMatchRequest
 UnityEngine.Networking.Match.NetworkMatch:CreateMatch(CreateMatchRequest, ResponseDelegate`1)
 SimpleMatchMaker___:CreateInternetMatch(String) (at Assets/Scripts/SimpleMatchMaker___.js:15)
 UnityEngine.EventSystems.EventSystem:Update()
     
 JSON Response: [[UnityEngine.Networking.Match.CreateMatchResponse]-success:True-extendedInfo:]-address:52.28.9.224,port:9999,networkId:0x0640000000020E42,nodeId:0x037F,usingRelay:True
 UnityEngine.Networking.Match.<ProcessMatchResponse>c__Iterator0`1:MoveNext()

Similarly recognisable result when joining the server too.

OnMatchCreate, OnServerReady and OnServerAddPlayer do not generate Debug.Logs and therefore I'm fairly sure they're not being called.

From reading the documentation I understand if the server is running at least one of those is supposed to be called? Can somebody talk me through making this work?

Code:

 #pragma strict
 public class SimpleMatchMaker___ extends NetworkBehaviour {
     var playerPrefab1 : GameObject;
 
     function Start() {
         NetworkManager.singleton.StartMatchMaker();
     }
     //call this method to request a match to be created on the server
     public function CreateInternetMatch(matchName: String) {
         var create: UnityEngine.Networking.Match.CreateMatchRequest = new UnityEngine.Networking.Match.CreateMatchRequest();
         create.name = matchName;
         create.size = 4;
         create.advertise = true;
         create.password = "";
         NetworkManager.singleton.matchMaker.CreateMatch(create, OnInternetMatchCreate);
     }
     //this method is called when your request for creating a match is returned
     private function OnInternetMatchCreate(matchResponse: UnityEngine.Networking.Match.CreateMatchResponse) {
         if (matchResponse != null && matchResponse.success) {
             //Debug.Log("Create match succeeded");
             var hostInfo: UnityEngine.Networking.Match.MatchInfo = new UnityEngine.Networking.Match.MatchInfo(matchResponse);
             NetworkServer.Listen(hostInfo, 9000);
             NetworkManager.singleton.StartHost(hostInfo);
             
         }
         else {
             Debug.LogError("Create match failed");
         }
     }
     //call this method to find a match through the matchmaker
     public function FindInternetMatch(matchName: String) {
         NetworkManager.singleton.matchMaker.ListMatches(0, 20, matchName, OnInternetMatchList);
     }
     //this method is called when a list of matches is returned
     private function OnInternetMatchList(matchListResponse: UnityEngine.Networking.Match.ListMatchResponse) {
         if (matchListResponse.success) {
             if (matchListResponse.matches.Count != 0) {
                 //join the last server (just in case there are two...)
                 NetworkManager.singleton.matchMaker.JoinMatch(matchListResponse.matches[matchListResponse.matches.Count - 1].networkId, "", OnJoinInternetMatch);
             }
             else {
                 Debug.Log("No matches in requested room!");
             }
         }
         else {
             Debug.LogError("Couldn't connect to match maker");
         }
     }
     //this method is called when your request to join a match is returned
     private function OnJoinInternetMatch(matchJoin: UnityEngine.Networking.Match.JoinMatchResponse) {
         if (matchJoin.success) {
             //Debug.Log("Able to join a match");
             var hostInfo: UnityEngine.Networking.Match.MatchInfo = new UnityEngine.Networking.Match.MatchInfo(matchJoin);
             NetworkManager.singleton.StartClient(hostInfo);
         }
         else {
             Debug.LogError("Join match failed");
         }
     }
     
 //    public virtual function OnMatchCreate(conn: NetworkConnection){
 //        Debug.Log("OnMatchCreate");
 //        NetworkServer.SetClientReady(conn);        
 //    }
     
     public virtual function OnServerReady(conn: NetworkConnection){
         Debug.Log("OnServerReady");
         NetworkServer.SetClientReady(conn);
     }
     
     public function OnServerAddPlayer(conn: NetworkConnection, playerControllerId: short) {
         Debug.Log("OnServerAddPlayer");    
         var playerPrefab = GameObject.Instantiate(playerPrefab1, Vector3.zero, Quaternion.identity);
         NetworkServer.AddPlayerForConnection(conn, playerPrefab, playerControllerId); 
     }
     
 }



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

0 Replies

· Add your reply
  • Sort: 

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

107 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

Related Questions

Setting the playerPrefab of network manager dynamically 1 Answer

Replacing NetworkManagerHUD button functionality 1 Answer

Unet - whats the best approach for a global game manager? 0 Answers

Unity network manager assign playerprefab at runtime 0 Answers

how to spawn a player prefab on a server 0 Answers


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