I use two assets that both declare their own Int2 - A* Pathfinding and SpriteTile. I can use them and Int2 fine. But how does this work?! Why isn’t Unity/Mono complaining about an already existing definition?
They’re most likely in their own namespace, created to avoid this very problem.
How does that work when I don’t reference the namespace? eg.
Int2 tempInt2 = new Int2(4,5);
I can pass tempInt2 into SpriteTile.whatever() and AStar.whatever and it is accepted and used. How does C# know which Int2 to use when I create the field? And why doesn’t it complain if I pass the wrong flavour of Int2 into a method expecting the other flavour?
If you’re in the same namespace as Int2 is declared in, you’ll be good.
Otherwise, you’ve probably imported only one of them with the Using statement. If you’ve got using AStar; on top of your file, any references to the name “Int2” will be AStar’s implementation. If you’ve got using SpriteTile, it’ll be SpriteTile’s version.
Assuming that the namespaces are named “AStar” and “SpriteTile” - they’re probably named something else, tho.
If you have BOTH imported, you’ll get compilation errors. Those can be fixed by putting the namespace in front of the name - so AStar.Int2 or SpriteTile.Int2.
Or if the implementations are the same you can refractor one out. Or add some implicit casting to ease things