Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Third Party Photon 2 - Question about non-player rigidbodies and syncing

Discussion in 'Multiplayer' started by smasters654, Jun 13, 2020.

  1. smasters654

    smasters654

    Joined:
    Dec 20, 2013
    Posts:
    46
    Hello,

    I have two questions I am hoping to get insight on for my project. I have searched the internet for a while and found similar questions but they don't seem to fit my particular case. So here goes:

    1. My project has a player count of 2 to 4. Each player can drop up to 3 rigidbody bombs at a time. Now the bombs will (hopefully) be able to be moved by contact of other players when bumped into by using forces. My question is to sync the rigidbody velocity and angular velocity of the bombs do I need a photon view on each bomb? I saw that having too many Photon Views isn't necessarily ideal and should be used for the most part as player controlled objects like avatars.

    I currently have a setup (which probably isn't good) where when a player presses the drop bomb input I send an RPC to all clients with the position and bomb prefab type(int) and a manager spawns the correct bomb locally on all clients from a pool at that position.

    2. I pre-load the bombs in the previously mentioned pool, so I don't think having a Photon View on each bomb is a good solution as there could be up to somewhere around 20 to 25 bombs pre-loaded between all the bomb types. What would be the best way I could handle this?

    Thanks for any ideas!
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,018
    Tricky, as there are various possible solutions with pros and cons.

    You can have more than a handful objects with a PhotonView on. Especially, if they are not all active / busy. Even if the OnSerializePhotonView would be called on the observed objects, your code can opt to send nothing if no update is needed.
    Before you optimize PhotonView counts, try the simpler solution.

    PUN 2 has an instantiation pool. Are you using that?
     
  3. smasters654

    smasters654

    Joined:
    Dec 20, 2013
    Posts:
    46
    Hi,

    I am using a pooling plugin called PurePool, which can be setup to use the PUN instantiation pool. So that I will be doing if I do put photon views on all the bombs. I really don’t want to go that route though.

    I saw on another forum post I could use one photon view to manage a hierarchy of gameobjects, which I am unsure how to go about in this case. If this is possible, do you have any insight on how the logic would work for that?

    Would I spawn the bomb into a parent gameobject, which has a photon view, then use that parent to sync the velocity/angular velocity of the child objects?

    Thanks!
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,018
    I am not sure if I understand exactly what you do and why.

    In the end, a script that is observable (implements IPunObservable) can wrap up any data it has access to. So, yes, it is an option to use one networked object (PhotonView) and write whatever comes to your mind about any object.

    Then again, you may not even need a PhotonView. You can also write any updates yourself and use RaiseEvent.
    https://doc.photonengine.com/en-us/pun/current/gameplay/rpcsandraiseevent
     
  5. shubhank008

    shubhank008

    Joined:
    Apr 3, 2014
    Posts:
    106
    tobiass please take a look at my thread too - https://forum.unity.com/threads/photon-pun2-non-rigidbody-lag-compensation-and-jittery-cars.912779/

    Posted in photon forums too but no replies to the point that I spent a week trying to make it work and ended up giving on it and moving to mirror