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 run_games · Jun 23, 2015 at 01:11 PM · networkingnot workinginstantiate prefabnetworkview

OnConnectedToServer, OnPlayerConnected, OnPlayerDisconnected not beeing called on instantiated prefab

Hi, I am having an issue with the network events above mentioned.

I have a mainSystem prefab, this prefab gets instantiated when the game starts.

This mainSystem prefab has a lot of custom components, and one of them is a customized networkManager( monobehaviour script)component. This component has one serialized gameobject public parameter, which I set in the unity editor to the reference of another gameobject prefab "NetModule" that has a networkView and a custom monobehaviour component on it.

The NetModule monobehaviour script has the event funcs "OnConnectedToServer" and so on on it. The NetModule prefab gets instantiated inside the networkManager using the Instantiate func, and the NetModule monobehaviour Start() func gets called so I assume that the Monobehaviour is correctly set up...

That is until I try to connect to another instance of the game ( Local or LAN )and expect that the OnConnectedToServer() gets called but nothing happens.

The strange thing is, if I put that same prefab on the scene using the editor, then that gameobject perfectly catches the OnConnectedToServer() event, so the connection procedure is fine as far as I can tell.

Also, if I declare the event funcs on the networkManager monobehaviour, the events get called without problem.

The basic source code would be something like this:

 // this is attached to the mainsystem prefab
 public class NetworkManager  : MonoBehaviour{
  public GameObject m_NetModule;
 ...
  void Start(){
   GameObject.Instantiate(m_NetModule);
  }
 ...
 
 }
 
 // this is attached to another GameObject prefab that is dragged into the networkManager as m_NetModule
 public class NetModule  : MonoBehaviour{
 
  void Start(){
   // this gets called when the network manager calls: GameObject.Instantiate(m_NetModule)
  }
 
  void OnConnectedToServer(){
   Debug.Log("Doesn't get called even if connected correctly to server.")
  }
 
 }

Any advice would be very appreciated!

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

2 People are following this question.

avatar image avatar image

Related Questions

Unity RPC mismatch 0 Answers

How to sync position only one time, using Photon Networking 1 Answer

Multiplayer Flashlight Issue 1 Answer

How to get NetworkViewID and GameObject attached to NetworkViewID 1 Answer

networkView not called on Child objects? 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