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
1
Question by Lynxxx · Sep 15, 2016 at 04:22 AM · multiplayerspawnclient-serverreferencingorder-of-execution

Order of Execution in Multiplayer

Hello

I'm currently working on a multiplayer game where I have some players and a ball I want to give randomly to a player. Now since the allocation needs to be random, the server has to chose the player and give it to each client. I do this in OnStartServer() but I only get one player when I search for my player objects with FindGameObjectsWithTag("Player"). The player objects are auto generated for each player by the NetworkLobbyManager. The scene loads fine by the way, with all players and not only one. That's why I think the OnStartServer() I call on the ball object (which is already in the scene unlike the player objects) is executed before all player objects are loaded.

Can somebody please explain me in what order all the objects/the functions (OnStartServer, etc.) are loaded/called?

Okay, second problem: When the server decides which player should have the ball (which is atm always the same because of the problem above), it saves it in a SyncVar with hook on a function that sets the parent for the ball. But this function is not called on clients (that are not hosts). When i give back the SyncVar in Update() it has a value (initially it is null). So why does the hook not trigger and execute the function as desired when it changes its value? Kinda confused by this one. EDIT: When i change the SyncVar after the game started (when I pass the ball to another player) the hook works perfectly fine. Maybe the client ball objects are not loaded yet when the server ball object changes the SyncVar value which results in the hook function not being executed on the client objects? Any idea how I can handle this?

Another problem I have is that I want to reference a GameController object to the player object. I assign it in the OnClientStart() and OnServerStart() with FindGameObjectWithTag("GameController"). This works when I host the game in the editor but throws "Object reference not set to an instance of an object" when I host the game with the standalone version. Does anybody have an idea what could be the cause of this problem?

As you see I'm slightly confused by when and how gameObjects and players get loaded on the server and the clients and how I should assign object references at runtime.

Thanks in advance for your help : )

Sincerely, Simon

PS: Would it help if I'd add the relevant snippets from my code?

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

· Add your reply
  • Sort: 
avatar image
0

Answer by toddisarockstar · Sep 15, 2016 at 08:33 PM

hmmmm. first of all, if you are using unity's master server there is nothing about gameplay "stored" on the server.

the only thing unity's master server does is give the players the other machines IP / port information so they can send data directly.

so with that in mind, if you want something random to happen for everyone, the random occurrence would have to happen in the code of only ONE of the players machines and then manually sent out to all the other players with an RPC call so everyone knows what random number was picked.

its very important in your online connection menu to make sure players scripts to know what player number they are and what belongs to who in your scene.

Nothing is automatic in multiplayer, anything updated must be sent out via RPC call.

generally a random selection like that would be done by the first player. usually called the "Host".

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
avatar image
0

Answer by Lynxxx · Sep 16, 2016 at 11:40 AM

I am using UNet. If I'm right the Unity Master Server is deprecated. And in UNet the server also has the scene loaded right? (Reference)

To solve all my problems at once, I was thinking about creating a function that checks if all elements are loaded. If this is true it would send a message to the server (via a command function) that the player has finished loading. On the server I'd start a coroutine that would trigger all the above described tasks (assign ball to a random player, load reference objects) on all the clients via an RPC call. I am aware that this is SUPER complicated and I really hope anyone can give me a better solution and a better overall understanding on how the UNet order of execution and instantiation works.

Sincerely, Simon

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 toddisarockstar · Sep 16, 2016 at 11:19 PM 1
Share

I looked at your reference and it does look like unity has added some new automated features to the new networking system which i haven't used yet. it's calling the host a server, which confuses me cause its impossible to create a network connection without a server on a static ip and listening port. So I assume they just decided to word it that way for simplicity to new developers. Anyways, it just seems like they are attempting to do a lot of stuff for you in the new system.

I think you have the right idea!, RPC calls are your way of manually sending data yourself. so sounds like you will need to send your own confirmation system to start one task before he next one starts. if you want an Online game, the coding gets "SUPER complicated". in comparison to single player. and you will notice that because of the complexity you won't get many people here that can answer multiplayer questions!

Welcome to the world of multiplayer!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Spawn players in unique places (Photon networking) Object sync problem for entering players. 0 Answers

Calling the Experts! Problems with Networking: Client/Server Architecture 1 Answer

Attach Canvas from Hierarchy to MP Player Spawn 0 Answers

StandAlone Server with SQL database for all clients 1 Answer

Rigidbody that two players can move/interact with over network? 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