Multi-player for non-scene based game.

Options
Hello, I'm creating a world builder game where users can create worlds which can get saved to disc, and shared with other users who can download and play. When a saved world is loaded, all the objects I the scene get instantiated at runtime. The saved worlds are not unity scenes. I'd like 2 users to be able to both load the same world, and then play in that world together. I'm wondering how this could work. Let's say the same world is loaded by 2 users, and the world contains a ball on the ground that can be picked up. How does the movement of this ball object get seen by both users? What I assume must be the case is that because all the objects (for each user) are instantiated at runtime, Photon would not have any way of knowing that a ball in for user A is the same as a ball for user B. This wouldn't be a problem for any static objects (walls, floors, stairs), because since they don't move, each player could maintain their own copy. I'm new to photon, so I suppose this is a newbie question. Is there a way to work around this problem?

Comments

  • Hi @BuilderWorldVR,

    by default you would use PhotonNetwork.Instantiate or PhotonNetwork.InstantiateSceneObject to create a networked object. The object you want to instantiate requires a PhotonView component. This component is basically a network identifier, but can be used for synchronization, too.

    Since this object is already in the scene, you would have to attach the PhotonView component (each client has to do this) at runtime and configure it properly. Configurating in this case means, that one client (the MasterClient) has to allocate a ViewId (identifier) for this object and apply it. He also has to tell each other client, to apply the same ViewId to the same PhotonView component. Also each client has to attach a PhotonTransformView component to that object. The PhotonTransformView component is a simple synchronization for the object. Additionally each client has to add this PhotonTransformView component as an Observed Component to the PhotonView component.

    This is similar to Manual Instantiation, but a little bit more advanced. So if you have the possibility, to turn the ball into a prefab, it would be much easier to network instantiate it.