Update position only once?

Options
Hey,

I am trying to update a position of an object only once and under specific requirement.

I guess I have to use RPC, however I have no idea how to implement it. I am aware of the way for OnPhotonSerializeView to update a position constantly. I also know I can do it the same way with OnPhotonSerializeView but I dont want to send messages when my object will not be moving at all once I want to update its position.

The idea is that either player click a button that spawns a 'building' at the mouse position and follow it until the player clicks with his mouse to place it. I want to update the position only when it is placed (clicked) that is why I needed synchronization only once!

thanks

Comments

  • Kurtav
    Kurtav ✭✭
    Options
    "Unreliable On Change" unfortunately sometimes loses position . So this is not an ideal solution to the problem
    Well yes. You argue the right direction. A special RPC that allows or does not allow the transfer of positions in OnPhotonSerializeView - if (stream.isWriting)
  • [Deleted User]
    Options
    Hi @HeadlessFly,

    The idea is that either player click a button that spawns a 'building' at the mouse position and follow it until the player clicks with his mouse to place it.


    I would instantiate this object only on the local client (no one else needs to see what and where you want to build something for now) and let it follow the mouse cursor as you already mentioned. When you now click the mouse button, destroy the locally instantiated object and instantiate a networked object using PhotonNetwork.Instantiate(...) with the placement position as parameter.

    I don't know if you want to move the building after it has been placed once, but if you want to you can use RPCs for that behaviour. It works mostly the same as before: when moving the building instantiate a local copy which follows the mouse cursor, when placing the build at the new position, destroy the local copy and make a RPC call on the networked object where you use the new placement position as parameter to inform every clients who is in the game.