Hello,
I have been working on a dynamic day cycle system for my game and am now struggling to get it to work on other clients. The error is Exception: cannot serialize(): DynamicDayCycle+DynamicData.
I am under the impression that PUN can only serialize basic data types such as numbers, bools, Vectors, etc. Well I have a couple class ‘packages’ that only contains these basic data types. Take a look:
/// <summary>
/// Dynamic data to serialize consisting of sun and weather.
/// </summary>
[Serializable]
public class DynamicData
{
/// <summary>
/// The sun data.
/// </summary>
public SunData sunData = new SunData();
/// <summary>
/// The current weather.
/// </summary>
public Weather currentWeather;
/// <summary>
/// The current time.
/// </summary>
public float currentTime;
/// <summary>
/// Updates the DynamicData package to serialize.
/// </summary>
/// <param name="position">The current position of the sun.</param>
/// <param name="rotation">The current rotation of the sun.</param>
/// <param name="color">The current color of the sun.</param>
/// <param name="intensity">The current intensity of the sun.</param>
/// <param name="weather">The current weather.</param>
/// <param name="time">The current time.</param>
public void Set(Vector3 position, Quaternion rotation, Color color, float intensity, Weather weather, float time)
{
sunData.currentRotation = rotation;
sunData.currentColor.Set(color);
sunData.currentIntensity = intensity;
currentWeather = weather;
currentTime = time;
}
/// <summary>
/// Sun data to serialize.
/// </summary>
[Serializable]
public class SunData
{
/// <summary>
/// The current rotation of the sun.
/// </summary>
public Quaternion currentRotation;
/// <summary>
/// The current color of the sun.
/// </summary>
public jColor currentColor = new jColor();
/// <summary>
/// The current intensity of the sun.
/// </summary>
public float currentIntensity;
/// <summary>
/// Serializable color class.
/// </summary>
[Serializable]
public class jColor
{
/// <summary>
/// Red.
/// </summary>
public float R;
/// <summary>
/// Green.
/// </summary>
public float G;
/// <summary>
/// Blue.
/// </summary>
public float B;
/// <summary>
/// Alpha.
/// </summary>
public float A;
/// <summary>
/// Sets this instance from a Unity Color class instance.
/// </summary>
/// <param name="color"></param>
public void Set(Color color)
{
R = color.r;
G = color.g;
B = color.b;
A = color.a;
}
/// <summary>
/// Makes a Unity Color instance from this serialized package.
/// </summary>
/// <returns></returns>
public Color ToColor()
{
return new Color(R, G, B, A);
}
}
}
}
/// <summary>
/// Weather types.
/// </summary>
[Serializable]
public enum Weather : int
{
/// <summary>
/// Sunny.
/// </summary>
None = 0,
/// <summary>
/// Foggy.
/// </summary>
LightFog = 1,
/// <summary>
/// Very foggy.
/// </summary>
DenseFog = 2,
/// <summary>
/// Light rain.
/// </summary>
LightRain = 3,
/// <summary>
/// Stormy conditions.
/// </summary>
RainStorm = 4,
/// <summary>
/// Light snow.
/// </summary>
LightSnow = 5,
/// <summary>
/// Blizzard.
/// </summary>
SnowStorm = 6
}
I believe that the only workaround would be to remove all the packages and have all of the data fields exposed in the base DynamicData class but that seems so rudimentary. Are there any better options before I do this?
Thanks