I feed two non-null gameObjects into the following method and they come out null:
[ClientRpc]
public void RpcSeenAction( GameObject sourceActor, GameObject targetActor, string seenAction ) {
if( sourceActor == null ) print( "No source object found on receiver " + name );
if( targetActor == null ) print( "No target object found on receiver " + name );
}
Both of those print statements fire, even though the GOs exist before the method is called. The string comes through fine. I guess the system is having trouble finding the net identities on the client after the RPC arrives. But why?
I’ve tried passing NetworkIdentity objects instead of GameObjects; this results in the same null references.
When I pass a NetworkInstanceId, I can get the correct value out of the struct’s Value property. However, if I try to use ClientScene.FindLocalObject with that NetworkInstanceId, it finds nothing. This is puzzling, since when running the client in the Editor I can select the GO I want, and the Network Information at the bottom of the inspector reports the correct number. So if NetworkInstanceId.Value reports 1 and the inspector reports the Network ID as 1, then why would ClientScene.FindLocalObject return null?
First things first are those NetworkIdentity objects present on the remote client? Have they been implemented using NetworkServer.Spawn() or the default player spawner? Is the client present on the list of observers for that NetworkIdentity?
Thanks for trying to help. The NetworkIdentity objects are scene objects (they are in the scene when the level is loaded), so they shouldn’t need to be spawned, right? I don’t want to have to make prefabs out of all these different scene objects, which represent dialogue encounters.
However, you’re right that there is only one observer in the NetworkIdentity.observers list, and its connectionId is -1. Perhaps I’m thinking about this wrong. Basically, I just want to send a reference to a GameObject from the server to the clients. That GameObject is present in the scene on both the client and the server and has no network behavior of its own. Is there an easier way?
In my first post, I mention that I’ve tried sending the NetworkIdentity and tried using ClientScene.FindLocalObject on the netId. Maybe there is a better way?
Woops I accidentally deleted my post even though I just wanted to edit it. (5 in the morning mistake)
Anyway what I wanted to say is that I’m not sure what the best way to sending GameObject/NetworkIdentity instances is over RPCs but there are specific Reader and Writer methods for that in the Network Messaging System.
Im not sure if theres a way to register scene objects automatically like you can in photon. I resorted to spawning my manager class as a prefab, its not a huge deal in the end and it can have its advantages.
They’re not. I presume that @powdered_swords is right that they need to be spawned even though they are scene objects. I’d like to find another way, if it exists, since spawning them means creating and registering a lot of prefabs that won’t get reused anywhere.
The netId is designed as a unique identify that is consistent across the network. So it should not be different on each client for the same object, as long as that object is handled by the network (has a network identity, is instantiated with ‘spawn’ on clients if not a scene object, etc…).