Search Unity

Bug [ServerRpc(RequireOwnership = false)] "loses" reference type data when not called on owner?

Discussion in 'Multiplayer' started by unity_PhblIVWzP3nRQQ, Feb 9, 2022.

  1. unity_PhblIVWzP3nRQQ

    unity_PhblIVWzP3nRQQ

    Joined:
    Jan 22, 2018
    Posts:
    2
    Hi!

    When I pass my data from the host (owner) through the Rpc it works just fine but passing it from the other client, it "loses" its reference type value. Is this intended?

    The data structure I intend to pass looks as following:

    public struct SkinnedCommand
    {
    public ushort commandId;
    public SkinnedCommandReferences references;
    }
    public struct SkinnedCommandReferences
    {
    public int[] entities;
    public bool clearQueueOnEnqeue;
    public SkinnedTarget target;
    }

    The value type data gets through just fine, the only thing that arrives as null is the int array. Is there a valuetype datastructure for the int array that might help me in this situation?
     
  2. CosmoM

    CosmoM

    Joined:
    Oct 31, 2015
    Posts:
    204
    References are not automatically serialized, which makes sense. After all, if you send data between different machines it's no use sending memory addresses, you have to send the actual data. Any structs like this that you want to send through Rpc calls therefore should inherit from INetworkSerializable. You can see how to do this, including for arrays, here.