#issue with network prefab

1 messages · Page 1 of 1 (latest)

high shore
#

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?"

verbal geyser
#

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...

high shore
#

@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?

verbal geyser
#

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

high shore
#

Thank you

high shore
verbal geyser
high shore
#

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?

verbal geyser
high shore
#

is there any posiblity to achive this?

verbal geyser
#

2 owners of a single object? No, you can't do that. There is a ChangeOwership() function you can if you need to.

high shore
#

okay

high shore
#

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 ?