Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 grandmapuckett · Jul 10, 2015 at 01:41 PM · unity 5networkingunity multiplayer

UNet - Where does "normal" code run?

First and foremost: while I have some experience with the Unity engine, I am an absolute beginner when it comes to Networking (concepts-wise and in practice), so I do apologize for any vagueness or confusion on my part. Also, it means that i'm approaching the topic from a high-level POV, as anything below the HLAPI is currently inaccessible to me.

When I attach a script to a GameObject, then spawn that gameobject across the network, is that script's code running on the server, the clients, or both of them? How many instances of that script exist and where?

I realize that this sounds like the answer would be "RTFM", but the documentation doesn't talk about this and often assumes that knowing the answer to this is a given, and while I did some tests, even when I make something work the way i want it to, I can't understand why it does, so I thought i'd be wise to pose the question directly.

By reading the documentation and tinkering on my own, I know that:

  • there are ways to make portions of the code run only on the server or clients (ClientRPCs,Command functions, etc). to be clear, my question refers to "ordinary" code, or code that would run the same even when not using the UnityEngine.Networking namespace.

  • UNet's architecture implies that, unless specified otherwise (with the "hasLocalAuthority" flag or in the case of playerObject),the server has authority on any network object.

Context: I'm trying to implement multiplayer functionality in a RTS game, and from what I understood so far, the best way to go about it would be to make it so that a good slice of gameplay stuff (such as units tracking, resources tracking, and generally anything that involves the status of the game) should be handled on the server and then trickle down to the client, while handling all the rest locally (all the aesthetical stuff like animations and sounds, UI, and generally all non-gameplay-related code). This means that, code-wise, there should be a strong separation between stuff that is ran only on the server and the rest, but I can't do that if I don't understand the basics of UNet first.

It seems useless to provide code snippets since this is not a specific case but a general doubt. I apologize if this sounds confusing or vague, but i can't figure it out on my own for the life of me.

Thanks, and cheers!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by seanr · Jul 10, 2015 at 05:59 PM

Code that is not part of specific UNet functionality is not changed. It will run "everywhere" - so on the server and on all the connected clients.

So a gameObject spawned on the host in a game with two remote players, will have three instances. One on the host (that is also shared by the "local client"), and one of each of the two remote clients.

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unet - NetworkServer.Spawn() correct usage 3 Answers

uNet Connection to IPv6 [Networking] 0 Answers

uNet Offline and Online Scenes the Same 2 Answers

In UNET LLAPI, two sockets with same ID and port on one machine 1 Answer

Time.time is influenced by the performance? Can i use it in a multiplayer game? 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