Transform2D restricted to nesting only objects of the same type?

I’m curious why Transform2D is restricted to nesting only objects of the same type?

For example, the below is not possible because M.Ex.Sprite extends Transform2D<Sprite> and so can’t have this Player object set as its Parent. This means I’d have to explicitly code mirroring player transform updates into any child sprites.

Or am I missing something?

public class Entity : Transform2D<Entity> {
...
}

public class Player : Entity {
    private Sprite sprite;

    public void OnEntry() {
        sprite.Parent = this;
    }
}

That’s a good question.

I wasn’t responsible for writing the Transform2D code. Looking at it, I don’t see any (obvious) reason why it needs to be that way.

However, as a workaround, maybe you can… oh wait… that won’t work.

Would you be interested in building from source and trying to fix the issue. I think we need to remove the TParent generic parameter.

Never-mind fixing it. I just removed it and everything appears to be okay.

It would be nice if you could test it in your situation and see if it solves your problem.

Later today (the build server is currently down) I’ll build a pre-release NuGet package. If you could reference that from your project the changes will be available.

Ah, beat me to it :slight_smile: I was going to say the only issue I found was that Parent is now a BaseTransform<TMatrix> not TParent so you might need a few extra casts here and there…

Yeah, that’s right. Time will tell if it’s really painful or not.

If it is, we might be able to do some other things like provide some helper methods or extra properties maybe.

Generics tend to be those “seems like a good idea at the time” kind of things but sometimes you later realize they can cause more problems than they solve. I think this is one of those cases.