Vector2Int looses values if used within polymorphic system

Issue #303 resolved
Former user created an issue


The issue seems like a bug, but I'm just starting to use Odin and I'm not sure if I'm doing everything correctly. In newer Unity versions, Unity added their own Vector2Int structure.

If you add Vector2Int field directly to a MonoBehaviour, it serialises properly, thus remembers given values.

If you add Vector2Int to serialized abstract class or it's implementation, it seems to serialise properly, but when you restart Unity or do a small change in code and recompile it, the field loses it's values and gets set to 0, 0.

public class TestBehaviour : SerializedMonoBehaviour {
    public Vector2Int properlySerialized;
    public abstract class Cont {
        public Vector2Int wronglySerialized; 
    public class ContImpl : Cont {
        public Vector2Int wronglySerialized; 
    public Cont cont;  

To reproduce it, just use the monobehaviour above. Then, change vector values in the inspector. Then do some change in your code, get back to Unity and see how values gets reduced to zeros.

Comments (1)

  1. Log in to comment