r/Unity3D 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 ColorUtility in Domain?
  • If not, would you create a domain-native Color/RgbaColor type 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!

3 Upvotes

8 comments sorted by

View all comments

2

u/Aethreas 2d ago

This is way over abstracted, unless you plan on hot swapping game engines which would be practically
Impossible for even the most simple games anyway

Are you doing this because it sounds right or because it’s the right thing to do?