Search Unity

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

How to correctly initialize a sync list in a base class for polymorphic usage

Discussion in 'Multiplayer' started by darthbator, Sep 22, 2016.

  1. darthbator

    darthbator

    Joined:
    Jan 21, 2012
    Posts:
    169
    So I have some polymorphic style items in my game, some of which share a common synclist of floats. However I've realized that the sync list does not properly initialize on the server if it's declared in a base class.

    protected SyncListFloat inaccuracy=new SyncListFloat();

    A sync list declared like that in the base class gives not initialized errors when I try and add an item in any of the derived classes. So I decided to leave the declaration in the base class uninitialized and just initialize it on the server in OnStartServer on the derived classes. However this doesn't appear to work either!!! I get the same uninitialized error on both the server and the clients. The only way I can get it to work is by both declaring and initializing the synclist in the derived class that addresses the synclist object. Is this a limitation of the HLAPI? How am I supposed to properly initialize synclists that are expected to be used in a polymorphic manner.

    EDIT : I went ahead and posted this to answers to. Why not update this here too!!!



     
    Last edited: Sep 22, 2016