Update information about a game object

MoDDIB
MoDDIB
Let's say I have a player which can create bombs.
During gameplay he can change colors and some others properties of these bombs.
When a new player connect I want him to receive the current state of these properties for each bombs.

When players are already connected there's no problem because I execute the command with RPCs, but for newcomers
I don't know how to proceed : another photonview just for that will be too heavy.

Watching the doc I saw and tried a RPC with PhotonTargets.AllBuffered.
That's ok it works, but if my color was changed 10 times it will send 9 times a RPC for nothing !
Is there a better way ?

Thank you

( btw my game isn't a bomb color game that was for explanation ;) )

Comments

  • Couple of things you can do.

    There is a function "OnPlayerConnected" (or something like that, look at the documentation. That is called whenever someone connects. You could look for that and then send the player the RPC call.

    I started doing something new on my latest game where I do a periodic update. For instance, maybe you want to send an update every second (and NOT every frame) you could do something like this...

    float periodicUpdateTimeLeft = 0.0f;

    [code2=csharp]void Update()
    {
    periodicUpdateTimeLeft = Mathf.Clamp(periodicUpdateTimeLeft - Time.deltaTime, 0, 1.0f);
    if (periodicUpdateTimeLeft == 0)
    {
    this.PeriodicUpdate();
    }
    }

    void PeriodicUpdate()
    {
    ... send some rpcs or whatever about the state of this thing

    periodicUpdateTimeLeft = 1.0f;
    }[/code2]
  • carmine wrote:
    Couple of things you can do.
    There is a function "OnPlayerConnected" (or something like that, look at the documentation. That is called whenever someone connects. You could look for that and then send the player the RPC call.
    So can you confirm that I have to write my own RPC call buffer ?
    I wanted to avoid it :/

    Periodic update isn't an efficient solution for my purpose.

    ( tip : you can avoid clamp each frame for a timer :) )
  • You could go one level deeper than Unity Networking (PUN) and use Photon's properties.
    These can be updated at will and are sent to players on connect.
    Per player (also a class in PUN), you can set custom properties and update them. Remove them by setting their value object to null.
    The keys of custom properties have to be a string. You should keep this short or use the least amount useful for you. Let say instead of "bombs" you name it "b" and the value is a byte[] of bomb positions. Color is "c" and an int (RGB part of the 4 byte aRGB color vector).
    The properties of a player are cleared when they leave. Room properties work the same way but exist in the room until all players left and the room is cleared.

    Check out Player.SetCustomProperties().
    Let us know how it works out for you.
  • It's interesting but if I want this to work I will need to send a lot more information like the gameobject to affect the type of setting and the setting itself. Each player will handle 10+ objects like this with 5+ properties each I don't think it will be really efficient.

    But I think I ll have to try it : it there an event when a property is modified ?

    Would be really great if each PhotonView could handle it's own properties !

    Thank you ;)
  • Well, if control of an object can switch, this always creates racing conditions. Even if all would happen on the same machine but with separate threads, this would be painful and you'd have to lock the object for control.

    I don't know enough about your game design (and I can't dive in too deep, really), so I don't know exactly how it could work.
    In worst case, I'd take a look beyond PUN and directly use Photon's events and properties. PUN makes assumptions what is an object and who is in control of that. This maybe can be solved easier when you start "from scratch" for this aspect of the game.

    I'm sorry that this is so vague but in the end, the topic has a lot of solutions and even more possible requirements.
    I hope this helps anyways.


    Properties per view?
    Ohno! Never!! :D
    Much too complicated. And a well known secret about Unity Networking on Photon is: The server has no clue there are PhotonViews at all. The magic all happens client side and the server just has abstract "events" being passed on (or cached).