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 /
avatar image
0
Question by Dudicus · Jul 11, 2017 at 12:20 AM · errornetworkingmultiplayermultiplayer-networking

The name `OnConnect' does not exist in the current context

I got some code for automatically joining matchmaking from StackExchange and when I tested it, it said "The name `OnConnect' does not exist in the current context". (I changed from MonoBehaviour to NetworkBehaviour too.) Here it is:

 using UnityEngine;
 using UnityEngine.Networking;
 using UnityEngine.Networking.Match;
 using UnityEngine.Networking.Types;
 using System.Collections;
 using System.Collections.Generic;
 
 public class GameLoader : NetworkBehaviour {
     bool done;
     // Use this for initialization
     void Start () {
         NetworkManager.singleton.StartMatchMaker();
         NetworkManager.singleton.matchMaker.ListMatches(0, 20, "Match", false, 0, 1, OnMatchList);
         Debug.Log("Searching");
     }
 
     public virtual void OnMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> matchList)
     {
         if (success)
         {
             if (matchList.Count != 0)
             {
                 Debug.Log("Matches Found");
                 NetworkManager.singleton.matchMaker.JoinMatch(matchList[0].networkId, "", "", "", 0, 1, OnMatchJoined);
             }
             else
             {
                 Debug.Log("No Matches Found");
                 Debug.Log("Creating Match");
                 NetworkManager.singleton.matchMaker.CreateMatch("Match", 2, true, "", "", "", 0, 1, OnMatchCreate);
             }
         }
         else
         {
             Debug.Log("ERROR : Match Search Failure");
         }
     }
 
     public virtual void OnMatchJoined(bool success, string extendedInfo, MatchInfo matchInfo)
     {
         if (success)
         {
             Debug.Log("Match Joined");
             MatchInfo hostInfo = matchInfo;
             NetworkManager.singleton.StartClient(hostInfo);
 
             OnConnect();
         }
         else
         {
             Debug.Log("ERROR : Match Join Failure");
         }
 
     }
 
     public virtual void OnMatchCreate(bool success, string extendedInfo, MatchInfo matchInfo)
     {
         if (success)
         {
             Debug.Log("Match Created");
 
             MatchInfo hostInfo = matchInfo;
             NetworkServer.Listen(hostInfo, 9000);
             NetworkManager.singleton.StartHost(hostInfo);
 
             OnConnect();
         }
         else
         {
             Debug.Log("ERROR : Match Create Failure");
         }
     }
 }

It's "OnConnect();" That calls an error.

Comment
Add comment · Show 3
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 Jwizard93 · Jul 11, 2017 at 03:15 AM 0
Share

The function doesn't exist. Why do you expect it to exist? Perhaps it belongs to another object and you need something like OtherObject.OnConnect();

avatar image Dudicus Jwizard93 · Jul 11, 2017 at 07:46 PM 0
Share

Exactly. I understand I might have confused you. But what I wan't is to figure out what it does to replicate it. I'm currently diving in source code trying to find an alternative for now (I don't feel like docs have a lot on Network$$anonymous$$anagers...).

avatar image Jwizard93 Dudicus · Jul 11, 2017 at 08:32 PM 0
Share

I can say they don't have any method called OnConnect() neither does any other class you are using. If you got this code from somewhere it was either using something that is no longer supported or you are missing the OnConnect() method that they had in their script.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by brockmcn · Jul 11, 2017 at 07:49 PM

You're trying to call a method with "OnConnect();" , but you don't have that method in your script.

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 Dudicus · Jul 12, 2017 at 11:57 PM 0
Share

I know that. I am wondering what that function would do, in speculation.

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

135 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

Related Questions

Unity networking tutorial? 6 Answers

Not calling OnServerAddPlayer() when client connect 0 Answers

Problems with Scene Change networking Unet 0 Answers

send data from client to local server 0 Answers

Validating User Actions on the 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