Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Quick question regarding Unity Netcode

Discussion in 'Netcode for GameObjects' started by TimothyUnity12, Nov 26, 2023.

  1. TimothyUnity12

    TimothyUnity12

    Joined:
    Aug 25, 2023
    Posts:
    2
    Hello. I am a relatively new Unity developer and the first post on this forum.
    If I mess something up regarding unity forums, please let me know, thanks.

    In Unity, there are ClientRpcs and ServerRpcs that allow the code to be ran on the client and server respectively (I think, tell me if I am wrong).

    However, what about methods not marked with [ClientRpc] or [ServerRpc]?
    A common method would be the Update method, y'know, the one that runs every frame.
    Would the code within the Update method be run on the client? Server? Both?

    (A little background into why I am asking this)

    I was following a YouTube tutorial about saving data (Using Unity Cloud Save Service), and it needed the "await" keyword.

    Unfortunately, ServerRpcs cannot be marked as async, so a workaround would be to create a new async method that will retrieve the data and return that value to the server rpc method.

    However, I am not sure if this data being retrieved in this async method is being executed by the client or the server. I do not want the client accessing and modifying (via hacks) the data before it returns a value to the server basically, so I need to know.

    Thanks.
     
  2. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    437
    Hi TimothyUnity12, they would run on the device on which you call them. Update is called autoamtically on active script instances, so if you have a GameObject with a Script that has an Update(), and both the GameObejct and the script component are Enabled on both the clients and the server, the update() will be called everywhere.
     
  3. TimothyUnity12

    TimothyUnity12

    Joined:
    Aug 25, 2023
    Posts:
    2
    Thanks for your response sir. That clears things up.