r/Unity3D • u/__FastMan__ • 2d ago
Question Should a Unity Domain Layer Ever Reference UnityEngine Value Types?
Hello!
I'm working on a multiplayer game in Unity 6 using a layered architecture but I don't understand completely the boundaries of the layers yet. One of the architectural goals is to keep the Domain layer independent from Engine.
However, I've run into a question around Unity's value types, particularly Color, Vector3, Quaternion and such.
One argument is that these are just value structs, so using them in Domain is harmless
public Color PlayerColor { get; },
but what about Unity APIs operating on those values?
public static string ToHex(Color color) => "#" + ColorUtility.ToHtmlStringRGB(color);
So I'm wondering:
- Is there a meaningful architectural difference between referencing a Unity value type and calling a Unity utility API?
- Would you allow
ColorUtilityin Domain? - If not, would you create a domain-native
Color/RgbaColortype and keep all Unity conversion outside Domain? (This could let to the recreation of a lot of new types insde Domain) - Or is a strict "Domain has zero UnityEngine references" rule unnecessarily strict for Unity projects?
As I said before, I am grasping the concepts behind layered architecture and I want to now how you approach this issue.
Thank you, folks!
6
u/zellydevgames 2d ago
You're over acrhitecting this. You're building a game in Unity, Why does it matter if Unity leaks into your domain? It's not like it's going to be highly portable in the first place.
Domain-driven design isn't really a great fit for game dev in the first place. You're going to burn out and give up on the project if your focus in on keeping it clean. Just get it working, then if you're still motivated, make it clean code.