# How to make a class diagram and data model of a Unity3D game?

I'm developing a 3D platformer video game on Unity3D and I've been asked to present its UML class diagram and data model. If I'm not mistaken Unity uses an entity-component-system, which necessarily doesn't use heritage. How would a class diagram from a Unity game look like, in that case?

Also, I've been taught that usually data model refers to entity-relationship-models that represent a database. In the case my game doesn't use a database, how could I diagram the way the player's data is store on the game? I'm storing the player progress on a file in the user's computer.

• "how could I diagram the way the player's data is stored in the game?" well, that depends on how you are storing the player's data. We can't help you to diagram your approach until you explain to us what that approach is. – DMGregory Jun 25 '18 at 1:06

I think you'll find that, as with software development in general, some Unity developers follow formal software engineering practices and some don't. Game development attracts more hobbyists, so the balance skews more toward off-the-cuff hacking, but I'd wager that a lot of large studios and professional developers use decent engineering practices. There's nothing stopping you from doing UML with Visual Studio Ultimate, or using Unity's Test Tools (with a nice tutorial now), etc

Patterns that fit well with Unity (Singleton, Observer, MVC ...). No complete drag-and-drop scripting, but rather some good concepts . When to use arrays, when to use Lists, Dictionarys etc, good libraries, sample snippets for various use cases.

Something that's kind of unity specific, the RequireComponent instead of just extending a class. Or a completely new diagramm type for Prefabs and their components.

Of course you can use external software. But code generaters and patterns turned out to be useless for me, since it's all a little bit different inside unity.

I think gathering those best practices and unity patterns might be worth to build in an asset that fits well within unity itself rather than some external software.

Its all depend on your game architecture. Which architecture you are following. For example if you are following MVC then you can draw diagram of model class and their relationship with each other, controllers and views same way. In Unity Views will be your Mono Classes.

It is possible to have MonoBehaviours which use inheritance, but in most Unity projects that's rather the exception than the norm. So an UML class diagram focusing on inheritance for a by-the-book Unity project would show many, many classes all inheriting from MonoBehaviour. But to improve readability, framework classes are usually omitted from class diagrams, so you would have a bunch of stand-alone classes not connected at all.

That would obviously not be very useful.

But what you could do instead is visualize dependency relations. Whenever one of your behaviors uses GetComponent<OtherMonoBehaviour>(), that behaviour has a dependency on the other behaviour. UML class diagrams have an arrow for that. When a behaviour keeps references to a group of other behaviours, then you have an aggregation. There is also an arrow for that.

You could also stretch the definition of "class" a bit and display different types of game objects as if they were classes. In that case:

• Prefab relations could be visualized as inheritance
• Objects which contain sub-objects can be visualized as a composition

Definitely check out doxygen. It's an open source tool which generates an API reference like documentation from source code. It's not the slickest tool out there but it does the job quite well and is used by many.

I use it from time to time to generate a technical but visual overview of all of the project's components. You'll get a good representation of how your code is organized and identifiy some design issues just by looking at some boxes and arrows. doxygen supports a couple of different languages like C/C++/C#/Java, so there's no issue by using Unity. It probably won't show you everything but it's a good start.

This is the (admittedly a bit dusty looking) general style of what doxygen does for you: