Inheritance and uninitialized synclists

I initially posted this to the MP forums here but haven’t had any luck figuring this out. The issue I am running into is with accessing or initializing a SyncList object that has been declared in a base class. Lets say I have something like this in my base class ThowableItem.cs

protected SyncListFloat inaccuracy = new SyncListFloat();

As long as I utilize this object within the ThrowableItem class everything works fine! However if I declare ThrowableItem.cs->Ball.cs and then attempt to access the inaccuracy element from Ball.cs I get an error that the sync list is uninitialized. This occurs even when attempting to access the inaccuracy object from a call to a base method. Here’s the code running in OnStartServer generating the error from ThrowableItem.cs:OnStartServer when called from Ball.cs

//	inaccuracy = new SyncListFloat();
    for (int count = 0; count < bagSize; count++) 
    	inaccuracy.Add(Random.Range(-inaccuracyRange, inaccuracyRange));

I also tried moving the initialization out the base class. I figured I would just initialize the variable declared in the base class in the descendant and everything would work. Nope, same error, synclist uninitialized. Do SyncLists need to be initialized within class scope and not method scope? How is it recommended to declare and initialize synclists for use with inheritance and polymorphism? I can’t seem to figure out how to correctly use these things within a class hierarchy.

I know this question is old, but I think it deserves an answer for anyone else who’s searching since I’ve been going nuts trying to sort this for almost a day now.

So the crux of the problem is uNet Weaver, the system that modifies and extends your code and classes to add all lovely uNet stuff. Weaver will add SyncList initialisation code to your class’ Awake() function, however (at least in version 5.5) it seems to have no awareness of class inheritance, and so the base class Awake () will be overridden by the inherited class.

The easy fix is to define a protected virtual Awake () in your base class and then override in all inherited classes (making sure to call base.Awake ()). These functions can be empty or not. The point is Weaver will not create its own “inheritance unaware” Awake functions, it will just add you SyncList init to these and everything will be fine.

Hope someone finds this useful