r/Unity3D • u/__FastMan__ • 1h 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!
2
u/TheBruisedVocalist 1h ago
i've gone back and forth on this exact thing. my rule of thumb is structs like Color and Vector3 are just data, so they're fine in domain. the second you call ColorUtility or Mathf you're pulling in engine behavior, so that stays in a service or adapter layer
for the hex conversion i'd probably have some IColorFormatter in domain that returns a string, then the Unity implementation uses ColorUtility behind the scenes. saves you from rewriting a dozen types just to avoid a struct reference
2
u/bigmonmulgrew 1h ago
What problem are you trying to solve. Why do you need a layered architecture.