- Home /
Rpc Best Practices and Multiplayer GameObjects in Scene
I have a GameObject
with a NetworkBehaviour
on it (call this object Grid). The Grid object is in the scene to start and is not instantiated by the server, it always exists. I have a basic input check in the update function and if the user left clicks it sends a ServerRpc
to spawn an object. This serverRpc
works fine when its the server sending it but when a client sends it I get the error "Client Trying to call a ServerRPC that requires ownership"
.
If I add the flag RequireOwnership =false
to the serverRpc
the call works just fine but I'm not sure if this is considered "safe" or not. So my question is:
1. What is the best practice for objects that are initially in the scene on startup to call Rpcs + other networking behavior
2. Is it safe to have the RequireOwnership
flag as false
3. Do all player actions have to go through the Player object that is instantiated for them when the join?
4. I can see this problem happening a lot with something like the players UI. I assume we dont do any networking on the UI but if the user clicks something like "buy" how does the UI communicate with the server through Rpc's? Wouldn't there always be an ownership error?
Hello, can you provide a sample of the code that spawns the object?
From my understanding, you have an ownership problem. The client that sends the ServerRpc needs to own the parent of the object that is being spawned. Otherwise, that would mean that other clients could control your character and spawn objects in your stead.
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Questions about Multiplayer and Networking? 1 Answer
OnStart ___ vs OnLobbyStart ___ methods from NetworkManager and NetworkLobbyManager 1 Answer
How to write a multiplayer game that uses a dedicated server? 0 Answers
Do Network Messages Use UDP or TCP? 2 Answers