Please help reduce my amount of Photon Views

Options
Hi guys,
I know Im using far too many Photon Views in my game, but I really dont know where I can afford to remove them. If I give a quick overview of my game, and explain why I am using a photon view, can someone please advise me of where I may have unnecessary Photon Views? The game is a small but jumpy, and so I really need advise.

The game is a two player survival game that is played out on a relatively large terrain. There are hundreds of trees, rocks, stone, animal AI etc. Its your typical survival game.

I have a photon view on the following: The players, the AI, all the trees, all other resources, switches & levers.

Trees: I have a photon view on the trees because I want to sync their position so both players see trees in the same place. When a tree is chopped, an RPC is called so all players see it fall over, and then wood is instantiated which all players can see. The observe is set to "none". I just use the photon view to call the RPC.

Other resources: Same as above. I have a photon view on stone, wood, and other resources so players all see it in the same position.

AI : My AI is moved using a nav mesh agent. I observe their transform using a PV. Should I add the OnPhotonSerializeView() function to their scripts? Because so far, I just observe their transforms while moving them based on their state machine.

Players: The two players have a photon view for obvious reasons. I know I dont need to remove that. Observe is set to the script that has OnSerializePhotonView()

Levers + Switches: I set their observe to "none", but when a lever is pulled, the handle of the lever moves, so I call an RPC so all players see the correct animation. Is this correct to do ?

Id really appreciate any input on any area mentioned above. Thanks so much :)

Comments

  • vadim
    Options
    Use single PhotonView object to control all the trees. It should maintain tree array in synced state between clients with RPC calls (create and chop). Same for levers, stones and other static stuff which does not change properties frequently.
    Moving things should have PhotonView attached in most cases (except simple movements, easy rendered from initial data as bullet has). Just keep amount of such objects below reasonable level.
    You do not need OnPhotonSerializeView() if observing transform works for you.
  • Thank you vadim, I'll change that today so its more efficient. Thanks You.
  • Cheyno
    Options
    Hi, I'm currently putting all my static object pickups into an array (a generic list actually),. I have a singleton item manager that caches all items in the scene at startup. When I pickup or drop items (via raycast), I send an RPC that tells other players to spawn or delete that item locally, as well as add or remove it from their own list.

    I'm wondering if this is a suitable approach. Also, I can manage each players list fine, but how do I pass the gameObject I want to spawn or destroy to an RPC, since it doesn't take gameObjects as parameters?

    Thanks
  • N1warhead
    Options
    @Cheyno yes you can pass a GameObject as a parameter. Or I can at least.

    GameObject SomeObject;
    void DoSomething(){
    myView.RPC ("SendToAllPlayers", PhotonTargets.All,SomeObject);
    }

    [PunRPC]
    public void SendToAllPlayers(GameObject obj){
    // Send this object to others, create it, whatever you want to do.
    }
  • Cheyno
    Options
    Really? Thanks, I seem to recall having a problem with this, but I'll have another go