MirrorNetworking / Mirror

#1 Open Source Unity Networking Library
https://mirror-networking.com
MIT License
5.26k stars 777 forks source link

isServer and isClient always false on Instantiated objects #3950

Closed Quetra1 closed 4 days ago

Quetra1 commented 5 days ago

Describe the bug When using Instantiate to create a non networked object, inside the Start/Update/OnTriggerEnter etc. both isServer and isClient are always false in the spawned object, regardless of whether the method is running on the server or the client. [ServerCallback] and [ClientCallback] work but even then isServer and isClient return false inside those methods.

As I'm new to mirror I assumed I was doing something wrong, but they return correctly when using non spawned objects (placed in scene prior to running). So I have to assume it's a bug unless I misunderstand some behaviour about spawned objects. I tried older versions of mirror and had same issue.

[IMPORTANT] How can we reproduce the issue, step by step: I made a template: https://github.com/Quetra1/isServerDemo

It's just a player object and spawned objects, arrow keys to move and press spacebar to spawn the object on the client and server using a [Command]. The Console will log isServer/isClient on Start/Update/OnTriggerEnter on the spawned objects.

Expected behavior isServer/isClient should return true when functions are running on the server or client respectively.

Desktop (please complete the following information):

MrGadget1024 commented 4 days ago

isServer / isClient aren't set until after NetworkServer.Spawn is called with the object. You're only instantiating the thing without spawning it.