- Home /
Unet host only code
I can't seem to wrap my head around how to run code only on the host. Not only on the hosted version of connected clients, but if I have code that I want to run only one instance of, and only on the host, how do I do that?
Answer by LK84 · Jan 17, 2017 at 07:03 PM
if(isServer)
{
// Your Code
}
That runs on the server copies of connected clients, thank you though.
I think you are misunderstanding some basics of Networking. There are no such things as "server copies of connected clients". It's hard to understand what you really want. Do you want a script only to run on the server? Then do (like I suggested):
if(isServer)
{
ServerGameObject.AddComponent<YourScript>();
}
Perhaps you misunderstand or don't care for my ter$$anonymous$$ology, but isServer will run on the instance/copy/etc of the local player object that exists on the server.
"... players are special kinds of objects. They represent the player on the server ... " I would call that server side representation of the client a copy or an instance.
Your answer

Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
UNET NetworkAnimator Compatible with Legacy? 0 Answers
[Multiplayer] Unable to spawn non-player object using NetworkServer.Spawn() call 0 Answers
NetworkTransport.Receive: how to drop an invalid message that is too long 0 Answers
Help with syncing non-player game objects with other players using UNet please? 0 Answers