I am working on replicating my game for clients. When a client interacts with an object, the interaction should replicate to all others, and the same should happen if the host interacts. I want to use a prefab for this. I tried using a local prefab, but it caused issues because it wasn't connecting to the server during instantiation. Then I tried using a network prefab, but it gets instantiated on all clients at the same time, which I don't want. How can I fix this?"
#issue with network prefab
1 messages · Page 1 of 1 (latest)
Networks Object have to get spawned on all clients for it to communicate. If you want to hide objects from certain clients, then you need to use Object Visibility
Object (NetworkObject) visibility is a Netcode for GameObjects term used to describe whether a NetworkObject is visible to one or more clients as it pertains to a netcode/network perspective. When a NetworkObject is visible to a client, the server will assure the client has a spawned version (a clone) of the NetworkObject. This also means that...
@verbal geyser In my project, I'm using a networked prefab. When it's instantiated, it becomes visible to all clients and the server. I want to override this behavior so that, although the prefab is instantiated and synchronized across the network, its visibility can be controlled individually on each client.
For example, suppose an image (or object) is spawned. It should remain inactive (invisible) by default for everyone. Then, when a player presses a button, it should become visible only for that player—while still syncing its data (like position, state, etc.) across the network. Is this possible?
Object Visiblity will despawn the object on the hidden clients. If you just want to disable the renderer, then you would either need to use RPCs to do that or maybe have Network Variable bool to control that
Thank you
Hi, I achieved it by activating and deactivating the network prefab's component like a canvas, skin renderer , and it's working fine. Could you please explain why I can't directly activate or deactivate the entire network prefab?
The network object/behavior components need to be active in order to receive network updates
Hey, I have one more doubt. I am instantiating a network prefab through the server, so after instantiation, only the server has authority over the prefab. Is it possible to give authority to both the server and the client at the same time?
No, an object can only have one owner at a time. Otherwise you'll end up with race conditions if both tries to change the object at the same time. You can request a change of ownership though.
is there any posiblity to achive this?
2 owners of a single object? No, you can't do that. There is a ChangeOwership() function you can if you need to.
okay
I want to know one thing: if we add a script related to interaction to a Network Prefab, will it work on both the client and server sides locally, just locally ?