Search Unity

Third Party Photon PUN Realtime Networked GameObject

Discussion in 'Multiplayer' started by seansteezy, Dec 5, 2016.

  1. seansteezy

    seansteezy

    Joined:
    Nov 28, 2013
    Posts:
    122
    What I'm trying to do:
    • player creates some game objects at runtime (dynamic 3d objects, like vertex based shapes and meshes, not prefabs)
    • player joins network/lobby/room
    • other players join the room and see the game objects
    What is working - players can join and see the others. Owner sees the game objects they themselves created. Other clients see nothing but the player avatars.

    I am very rusty with this stuff, sorry for my ignorance.

    Since I can't create prefabs out of the objects to instantiate, I was trying to assign the observed components of the PhotonView when they're created and it's not working. Returns null for view.ObservedComponents.Add(componentToObserve), saying view.observed = componentToObserve doesn't work either.

    Anyone have any ideas or thoughts? This is pretty simple stuff so I have no idea why I can't get this to work.

    The objects are mostly static, only need to be updated with RPCs for things like color change or material change, location, rotation, etc. Someone suggested doing an RPC to attach the components (PhotonView) and then set the observed component but that's not working either, still null. I am thinking maybe using RPC to send the game object info so it can be reconstructed on the client side? It's a bunch of simple meshes, just need verticies, and material name. Would that work?

    There is only 1 scene in the project. They click a button and enter a networking room. Clients drop into the master's scene.

    If anyone can help I'd greatly appreciate it! Thanks,

    -ss
     
    Last edited: Dec 6, 2016
  2. Kamil-Says

    Kamil-Says

    Joined:
    Jun 30, 2014
    Posts:
    154
    Any code...? Just instantiate the object without any extra photonview on it and manage it with your base PhotonView. What's so hard?
     
  3. seansteezy

    seansteezy

    Joined:
    Nov 28, 2013
    Posts:
    122
    Hey there Kamil, thanks for the response!

    I guess my issue is, these objects can't be instantiated because they don't exist until runtime. The user creates 3d objects in the application, and when they go into a room, other people should be able to see these objects, so I can't save them as prefabs and instantiate them on the network. Looking for the proper way to make that happen... any ideas?

    My first thought is to pass info about the objects so the clients can recreate them with a RPC, but then I would have like a mirror situation going on where every client has a copy of the actual object, but I want them to just be seeing the actual object that the master has. These objects exist before going into multiplayer and while in multiplayer.

    I was trying to add the photon view to the object as it is created, and set it's observed components to scripts on that same game object, but it just doesn't let me, and nothing happens.
     
  4. seansteezy

    seansteezy

    Joined:
    Nov 28, 2013
    Posts:
    122
    I may be super dense tho, and might be missing something very basic?
     
  5. seansteezy

    seansteezy

    Joined:
    Nov 28, 2013
    Posts:
    122
    It looks like after some research that this can only be done by serializing my data, then passing that data to other players to reconstruct the 3d objects through RPCs. It doesn't really effect performance in my case since these aren't highly dynamic objects, so whenever an object changes, I just send the call to update it through the network. Not an optimal solution but it works and that's all I care about for now.

    In my case, I am saying, the master has a list of vectors for this 3d object, send that data to the clients through RPC and run the build function locally so it can create a 3d mesh with the same properties as the master's object. If the master edits the object, send an RPC with the updated info to update that object across the clients.

    I didn't want to have this copy object thing on here, I just want master objects to propagate across the network if anyone has a solution that is more streamlined, I'm all ears.

    Thanks!

    -ss
     
  6. Kamil-Says

    Kamil-Says

    Joined:
    Jun 30, 2014
    Posts:
    154
    Show us some code/way you "create" these objects in runtime, then we will know more.
     
  7. seansteezy

    seansteezy

    Joined:
    Nov 28, 2013
    Posts:
    122
    The host opens the application, it loads the main scene and they click around on plane and place points in 3d space, so we have an array of vector3's (vertex position) which we create a mesh with using the procedure that Unity describes here, setting verts, tris, uvs, etc. Nothing special.

    I create empty game objects and then the mesh component is added where we define it's properties, while the app is running. I can attach any scripts and a photon view component to that game object when it is created (the object comes into existence by defining the properties of it's mesh component). Then the player would be entering the multiplayer room with these objects in their scene, and at that time I would like to begin the serialization to pass the object info to others in the room. Trying to figure out what I need that object to have attached to it in order for the other players to "see" it.

    Appreciate you trying help, sorry I can't be more detailed, the algorithm we use to create these mesh objects is a trade secret.
     
  8. Kamil-Says

    Kamil-Says

    Joined:
    Jun 30, 2014
    Posts:
    154
    "Then the player would be entering the multiplayer room with these objects in their scene, and at that time I would like to begin the serialization to pass the object info to others in the room."

    How does the object still exist while loading (usually everything gets destoried) new room level and how should the room you joined know what you made in menu scene when it's not even synced? o_O? Or did I missunderstand that right now?
     
  9. seansteezy

    seansteezy

    Joined:
    Nov 28, 2013
    Posts:
    122
    We have one scene, the user is not hooked into photon at the start but can press a button and join the network and enter a room (unique room per user - so each user has their own room based on their name + random number).

    It works fine when instantiating players from a prefab, as we can all see and talk to eachother while moving about, but the 3d objects created by the host are not visible to anyone else.

    I am wondering how to tell photon there are objects here that need to be sent to the network and displayed to the clients?

    The remote players all have photon views and the observed component is a "networked player" script on each player. It sends data about their position and rotation. Why can't I do this for random objects? Maybe it's my own ignorance about networking?

    I know this is a weird use case, not your standard stuff, and we may be breaking some rules, but if I can get players to work (instantiated through prefabs) how would I get objects created at runtime to act as though they are instantiated the same way? Do I create copies of them and instantiate on client side, then just update them through RPC? My current solution is passing the object data to the clients and having the client build the mesh using that code, it works since we're not in a highly dynamic environment (no bullets or action) but I feel like there may be a better way.
     
  10. Kamil-Says

    Kamil-Says

    Joined:
    Jun 30, 2014
    Posts:
    154
    The probably best way would be just to pass the data via event and let the other clients recreate the object with the given parameters.
     
  11. seansteezy

    seansteezy

    Joined:
    Nov 28, 2013
    Posts:
    122
    Thanks for your input! I figured that was the only way, but am still holding out hope there is some magic that can be done :)