Search Unity

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

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


    Jan 22, 2018

    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


    Oct 31, 2015
    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.