14 ms·
Basic Concepts in Unity for Software Engineers
- Pfhreak 6y agoI absolutely love Unity, and it's what I reach for as my default for new projects, despite several years working in the games industry. It's easy to get started, iterate on ideas, there are tons of examples of things online. That said, it's not without its warts -- APIs change constantly, which means many of the examples or assets you find are no longer functional or need to poking to get working. Sometimes things just... behave oddly... in the editor. And the story around collaborating with friends is still not great (though a free tier for Unity Collaborate has helped with this a bit.) If you haven't messed around with Unity, I encourage folks to give it a try. The new Universal Render Pipeline stuff they've been building is really nice for a solo/small team project.
- andyfleming 6y agoI’ve had frustration with the warts you describe. Have you tried Godot? Any idea if it’s any better in those regards?
- offtop5 6y agoGodot isn't finished yet. Unless you plan on developing an open source game or need absolute total control over your project I wouldn't use Godot. The greatest advantage of Unity is anyone can develop something for it very fast. The worst part of Unity is anyone can develop something for it very fast. An asset developer might build something which he or she doesn't actually update, or has a nasty habit of completely breaking your project. The one thing I don't like about Unity is the lack of quality control with assets. Some assets will give you a nice foundation for a fantastic project, others will set you back days. Asset authors are almost always either absolute Angels, who will go out of their way to help you and if they can't offer you a refund. Or their jerks, their assets don't do what they promised and they'll refuse to refund your money. If I could fix one thing about the unity ecosystem, I'd tell Unity to give asset buyers a few no contest refunds . I probably spend about 1000$ on Unity assets per year. The one time a $15 asset ends up not working correctly I should be able to get a refund without begging the author for it. Plus it's essential to understand what your goal is. Do you want to actually ship your game within a reasonable amount of time? Or do you feel like creating a project primarily for learning, or to just share the code on GitHub? If you want to ship a game, either use Unity or Unreal. These are the only two engines which are well supported enough where you can get something done within a reasonable amount of time. Open source engines are cool, but there is absolutely no expectation of things working as well. Let's say you want to build a project with Godot, and it's going well so you want to publish it to Switch. You're going to run into a ton of problems off the bat, one open source projects tend to not support closed apis which council manufacturers force you to support. So you're going to have to build your own integration there. Vs clicking a build to Switch button with Unity. Honestly I can't say enough good things about Unity, you have an amazing amount of educational material they publish. And for the most part I've been able to buy assets for $50 or $100, and save myself 80% of the development time on my projects. You aren't going to have a good time with Unity if you're adverse to buying assets.
- Kiro 6y agoWhat kind of assets are you buying? I thought most assets were character models and such but sounds like you buy assets with actual functionality. Do you have any examples?
- offtop5 6y agohttps://assetstore.unity.com/packages/templates/systems/corgi-engine-2d-2-5d-platformer-26617 https://assetstore.unity.com/packages/templates/systems/corg... That's basically a 2D / 2.5d game framework.
- Kiro 6y agoInteresting. Is this essential for people making 2D games in Unity? I see that it's officially recommended by Unity themselves.
- rubito 6y agoIt’s not essential but this is one of Unity’s revenue sources, so they will advertise it . In fact, one key aspect to finding success (disclosure: I am an ex Unity AssetStore publisher) in the AssetStore is to persuade buyers in thinking your asset is essential for making their project come true. It’s all about selling shovels and dreams.
- jpindar 6y agoWhere is it officially recommended? There is other content that is created by Unity but that is clearly labeled as such. Nothing from the Asset Store is essential, but it would take much longer to do everything yourself from scratch, as well as being difficult to learn how to do everything yourself without examples to experiment with.
- Kiro 6y agoI think it was this part: > The Corgi Engine is recommended by Unity as part of its 2D Essentials Pack. Maybe I read too much into it.
- bj-rn 6y agoFor another alternative (especially if you want to stay with C#) have a look at https://stride3d.net https://stride3d.net
- dleslie 6y agoThe most important thing about Unity is to know that the Editor is not the same as the Client. Assets load differently, in surprising ways. Materials may work fine in Editor but not in Client. Code executes differently. Timings are different, the Editor shares managed Heap with the Client, and so garbage collection is different. And so on. Rule 0 with Unity: _do not rely on the Editor for testing_.
- cmeacham98 6y agoHot take: to some extent, this is a good thing as it discourages relying on emergent behavior in the client, like timings, the heap, etc that may or may not differ between your machine, your player's machines, and even future hardware that does not exist right now.
- Eyas 6y agoI'm with you there, but (and, this is an unpopular opinion) I think it would be even better if it went the way of Go. Go will randomize iteration order of unordered collections (at least in development builds?) on purpose so you learn not depend on it. The "tricky" thing with Unity is that you might find a consistent client behavior and unknowingly depend on it. I think with time/experience you'll learn to spot what to ignore (frame lengths, etc) and what you could count on. And just to test fully-build games often, and across clients. * C# does something similar with hash across builds (so you don't depend on serializing/deserializing hashes and expect them to work; they want the freedom to change hash functions).
- conradludgate 6y agoGo doesn't randomise map order, it's just indeterminate. It picks a lot random bucket to start the iteration but the order will always be the same in the end (at least when I last investigated it). It's essentially free, so it does it in production too
- jayd16 6y agoDon't rely on race conditions and your code will run similarly on device and in editor. I agree that you can't easily use editor performance profiles though; there's far too much editor noise.
- learc83 6y agoI finally ditched Unity because I’m sick of compile times in the newer versions of Unity. It’s been getting worse since 2017 or so and it finally got to be too much for me. I’ve switched over to the Heaps engine by the creator of the Haxe language. In addition to the compile time issues, I found myself constantly fighting the Unity way of doing things in that I prefer doing things in code as opposed to using the editor.
- Eyas 6y agoI'll have to check out Heaps. But you're totally right that the "Unity way" of using the editor isn't how a lot of us would naturally gravitate to creating a game. I learned to like it, though (I think). For me, I realized that wanting to "keep it all in code" is a learned habit, and part of why I learned it is because the tooling when everything in code is just so much better. I can navigate references, etc., count on compiler errors runtime errors, etc. But none of this fundamentally required me to keep it all in code _if_ the tooling allows it. With ~2020 it feels like the tooling is getting to that point.
- learc83 6y ago> But none of this fundamentally required me to keep it all in code _if_ the tooling allows it. With ~2020 it feels like the tooling is getting to that point. I don't think Unity is nearly at that point for my use case. Part of the problem is that I tend to build games that require a lot of procedural generation and user created content. I basically end up needing to build some kind of level/content editor for my end users, which removes a lot of the value Unity brings to the table.
- ratww 6y agoYeah, the usefulness of the editor really depends on the workflow. If you're using procedural generation or using an external tool to design your levels, then the Editor definitely becomes a hurdle.
- thurn 6y agoHuh, I've always found Unity orders of magnitude better than something like Unreal, never seen more than 10 seconds to compile which seems quite reasonable to me. (You do need to turn off Auto Refresh though, no idea why they think having that setting enabled by default is a good idea.)
- sanjeetsuhag 6y agoIs there anything similar for Unreal Engine?
- rudedogg 6y agoIf you haven't already, check out the Unreal Engine Youtube Channel: https://www.youtube.com/c/UnrealEngine/videos https://www.youtube.com/c/UnrealEngine/videos.
- thurn 6y agoIt can be quite hard to come to game development from a web programming background, because "good architecture" for a React app means a set of best practices (e.g. one way data flow, immutability, discrete mutations and events) which don't always cleanly map over to a realtime environment. It might be good to talk about mapping over concepts you're already familiar with.
- runawaybottle 6y agoOddly enough, I was looking into grabbing a Unity book earlier this week. Any recommendations would be welcome. One thing I noticed from just skimming the tutorials is there is a lot of Unity editor specific creation of stuff. How much of that is the actual game programming? Maybe web dev is headed in that direction if we ever eventually map Figma to components, where you kind of define it via a GUI. Seeing that felt a little off putting since I’m used to working with a tight scaffold that’s mostly code. Godot looked less GUI intensive so I was thinking about digging into that instead. I guess another way to pose this question is, do I need to get over this and accept this is how games are made?
- Eyas 6y agoThere is a market for purely code-generated games, and especially so with procedurally generated games. But honestly, for most cases, yes I think the 90th percentile answer is to get over this. I kind of wrote about "keeping it all in code" and why it isn't desirable in the second installment: https://blog.eyas.sh/2020/10/unity-for-engineers-pt2-six-practices/ https://blog.eyas.sh/2020/10/unity-for-engineers-pt2-six-pra... But once you get the placement / connection / injection right, you'll still be spending the bulk of your non-testing development time in the code editor.
- runawaybottle 6y agoHah, you literally addressed my concerns in the article. Will sub, thanks for the read.
- Eyas 6y ago
- dcre 6y agoNice post. It’s worth noting that a post like this doesn’t need to be written for Godot because the official docs are already this good. https://docs.godotengine.org/en/stable/getting_started/step_by_step/index.html https://docs.godotengine.org/en/stable/getting_started/step_... After spending literally hours trying and failing to get Unity to run at all on my computer, I downloaded Godot and ran a demo project in 5 minutes. It’s a great lighter-weight option for software developers who want to feel a little closer to the code.
- khalilravanna 6y agoNext time I jump into game dev I definitely want to try Unity. Last time I wrote my own engine pretty much from scratch on top of Pixi.js and while I learned a huge amount, there were a lot of “lessons learned” that I gained manually (or didn’t gain) that Unity has baked in from the start. One thing that’s interesting to me about Unity is AFAIK it bakes the Entity Component System pattern into its core. Any good guides or resources on this? I found Robert Nystrom’s excellent book a good resource for this (http://gameprogrammingpatterns.com/component.html http://gameprogrammingpatterns.com/component.html) and even wrote my own post on the concept to help crystallize my understanding (http://ripplega.me/development/ecs-ez/ http://ripplega.me/development/ecs-ez/). I’m interested to see if there’s a good authoritative Unity-specific post on the topic.
- Eyas 6y agoReal DOD-style ECS is being baked into the core of the "new way" of programming Unity, but a lot of that is in preview packages. Much of how Unity is used today actually involves very little ECS. See https://unity.com/dots https://unity.com/dots
- anchpop 6y agoUnfortunately they've been quiet about when we can expect the new features to start being ready for testing - there was no news about DOTS in the new 2020 point release for instance
- raxxorrax 6y agoIt is not dogmatically following any patterns, but looking at some modding tools of Bethesda games is interesting for how game data as entities or forms in this case is structured. Battle tested model for extendibility and you already have real game data to get examples. Don't know how close these patterns would fit Unity, but I would suspect a large overlap.
- finikytou 6y agoquick question on unity vs unreal engine. the more i see the future the less i see one for unity vs unreal especially with movies using unreal engine in the last 2 years (really from the movie first man to now most of the new movies) i feel the money and R&D that will span from that in the unreal engine will allow them to totally crush unity. already today most of the modern games made with unity are 2d or average 3d games. What is your take on that?
- Eyas 6y agoUnity is unlikely to unseat Unreal as the primary engine used by AAA games/movies, but it still has a decent share in both AAA games and movies. Still, the game engine market is unlikely to be dominated by a single player anytime soon. I think you'll continue to see something that looks rather similar to the mobile OS space: lots of players, but ~2 dominate the space. Unreal's revenue cut is also a lot more prohibitive than Unity's, so you'll also keep seeing a healthy indie ecosystem (which translates to a community, assets, etc.) in Unity. A lot of Unreal's recent investments are incredibly impressive. Especially with better rendering and realtime raytracing. But Unity is also making some big investments, DOTS (see https://unity.com/megacity https://unity.com/megacity for example) comes to mind in particular.
- gamblor956 6y agoBoth Unity and Unreal are used by Hollywood studios for different things. Unreal is used for on-set visualization (see e.g. the Mandalorian) but Unity is frequently used for pre-viz/planning work because you can just literally drag and drop things in and run them (see e.g. the Jungle Book, from the same director). i feel the money and R&D that will span from that in the unreal engine will allow them to totally crush unity. already today most of the modern games made with unity are 2d or average 3d games. Most of the modern games today aren't made with the Unreal engine...For example, among triple-AAA studios, EA, Rockstar, Activision, and Ubisoft all use their own engines (note: Activision uses Unity for some of its games). Epic already makes a few hundred million each year from Fortnite. The relative pittance they get from Hollywood studios isn't even a drop in the bucket and generally won't effect the pace of development of Unreal, though it has driven Epic to put even more effort into making Unreal a better component in Hollywood workflows. However, this effort won't have much, if any, impact on game production since the workflows are completely different.
- holografix 6y agoThank you, subscribed to the blog!
- Waterluvian 6y agoCan Scenes be stitched together? Say I wanted to keep loading open world tiles as my character walked a long distance.
- offtop5 6y agohttps://docs.unity3d.com/ScriptReference/SceneManagement.LoadSceneMode.Additive.html https://docs.unity3d.com/ScriptReference/SceneManagement.Loa... Sure , you can add more scenes . I've never done it to create terrain though. Another trick is to not destroy certain game objects on load.
- klodolph 6y agohttps://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html https://docs.unity3d.com/ScriptReference/SceneManagement.Sce... See “mode” parameter—additive. This doesn’t answer how you unload.
- PudgePacket 6y agoYes, multiple scenes are common practise. Using it to stitch game worlds is not common though. Most terrain systems would have their own, more optimal/efficient ways of doing that. https://docs.unity3d.com/ScriptReference/SceneManagement.LoadSceneMode.Additive.html https://docs.unity3d.com/ScriptReference/SceneManagement.Loa... https://gamedevacademy.org/a-guide-to-handling-huge-worlds-in-unity-part-2/ https://gamedevacademy.org/a-guide-to-handling-huge-worlds-i...
- Eyas 6y agoThat might be true for for some terrain systems, but AFAICT it is still common for other objects (e.g. units, buildings, etc.) to be loaded like that.
- gamblor956 6y agoYes, in 2020 Unity introduced the concept of "SubScenes" which allow for large worlds (i.e., MMO-style loading).
- duncancarroll 6y agoThis is great! I've been looking for something like this everywhere; thank you for writing it and I look forward to reading the next installments.
- throwawaysea 6y agoFor those who are experienced in this space, which of these game engines/ecosystems named in this discussion (Unity, Unreal, Godot, Heaps, perhaps others) are easy to approach and learn?
- mhh__ 6y agoUnreal is really badly documented for the most part. The basics are described, and the overall architecture of the engine is outlined but for most of the C++ codebase you either have to translate from blueprint code in your head or guess based on usage you can find in the epic code (i.e. most of the documentation for their containers has no examples or best practices so I have to read the code to find out how it behaves)
- klmadfejno 6y agoCan only speak to unity and unreal. I got up and running faster with Unity in 1 week. But after 1 month with each I found unreal to be easier. A major problem with both is that the learning communities are terrible, because they're filled with wannabes who, while well intentioned, have no idea what they're doing. Question and Answer forums are plagued with dumb questions that aggressively try to assert that they need to know X when actually the problem begins at A, B, C. Youtube tutorials are filled with hilariously bad narrators who spend an hour trying to demo a basic concept and then for unfathomable reasons, do not show the final result before ending the video. Find a single good set of tutorials to go through the process of making something (anything!) and an active place where competent people discuss things. Googling, unlike most coding problems, is not your friend if you want to find best practice stuff. For Unreal, I thought this guy was decent: https://www.youtube.com/watch?v=DywBqQtTHMo https://www.youtube.com/watch?v=DywBqQtTHMo I only did the first fifteen or so before I decided to start figuring stuff out on my own. The unreal slackers discord channel is the best place I've found for asking knowledgable folks.
- nits1234 6y agohello
- mattlondon 6y agoI enjoy tinkering with Unity. One thing that I am struggling with though is settling on good ideas for general architecture for structuring the logic, and then doing things like communicating between entities/objects in a scalable way. Not everything that needs to communicate exists in a nice parent-child relationship - occasionally you need to communicate "across branches" in a hierarchical tree when there is no other interactions such as collisions etc. You can get a long way with just cobbling stuff together, but eventually you get into growing pains where it becomes a mess. The "best" solution I have so far is awkward "god"/"manager" objects that act as glue to let everything access everything. There has to be a better way? The nice with with Unity though is that the logic is in .NET IL so it is trivial to see how people are doing things and learn.
- meheleventyone 6y agoTypically games use a messaging system similar to the sort of thing you'd expect implementing the Actor model. This lets you keep things decoupled whilst still leaving them the ability to communicate. It's pretty handy but also needs to be used with care if you're not going to invest a bunch of time in writing tools to support it as it makes debugging tricky. Don't be too worried about mediators though. Games are a little bit different in that you typically want to act on a shared world. If you have systems that act globally on the world then you're just matching the data that exists. Even the physics system itself is basically a singleton that's mediating interaction.
- FroshKiller 6y agoI haven't used Unity much, but I know components are a big deal. You add components that define things like an object's collision behavior or what audio it plays, and when you need to use those components in a script, it has a service locator approach to retrieving an object's components.
- Jorge1o1 6y agoThe best way to communicate across hierarchies is to set the other GameObject/Component that you need to communicate with as a public field and then manually set that GameObject via the Editor so now the UI has a reference to the Player’s Gun’s AmmoBehaviour. You can then use Events and EventHandlers to have the UI subscribe to every shot and now it can show how much ammo is left in the gun. This can get kind of tricky if you use a lot of procedural generation or prefabs where for some reason you can’t immediately set the reference to that other GameObject (for example, the player has no gun yet). In those cases you should try to set the reference programatically, such as when the Player picks up the gun. You might have a reference from the Player to the HUD, and when the player picks up the gun you set the Gun’s UI reference via some SetUiObject(GameObject ui)
- smusamashah 6y agoA bit similar https://catlikecoding.com/unity/tutorials/ https://catlikecoding.com/unity/tutorials/
- klmadfejno 6y agoHobbyist game dev who's dabbled in Unreal and Unity with no CS degree and no experience in C# or C++ (but a fair amount of python). Both are fine, but if you're going to pick one, I'd suggest Unreal by a long shot. Switching between the two is tricky and is likely to make one feel whichever they started with is more intuitive as the UI design is pretty different for each editor, but both feel fine after a short effort. The main reason I'd vote for Unreal is that Unreal feels like it's getting better at a noteworthy pace, and Unity is stuck in a one step forward, one step back pace. * C++ (unreal) is not as fun as C# (unity). But Unreal's blueprint system (a visual, node based coding system) is much easier than both, and super helpful in the game dev world because it makes the engine API easily discoverable. Not good if you want to write a list sorting algo. Very good if you want to make a character jump. Dispense any preconceptions they may have implied about "not needing to know how to code" to use blueprints. If you can't code you will likely burn out trying to use blueprints without grasping the fundamentals of coding, because blueprints are just code with visual syntax, and syntax is not the hard part of coding. * Marketplace assets on unreal seem way better. The high end stuff is better. The free stuff is better. The number of high quality textures and prefabs you get for free via quixel in Unreal is astounding. * Unreal requires more computing power, and I found the editor crashes more. That's not so good. * Networked multiplayer is just broken in Unity, versus integrated into everything for Unreal. This is huge! for shame, unity. * Unreal's financial terms are more indie friendly (free for first million of revenue) * Neither is going to make or break your game dev experience versus the other.
- jscheel 6y agoI would love to use Unreal, but just having a blank scene in the editor open makes my fully loaded 2019 16" MBP's fans go full hog.
- quxpar 6y agoSame! I am trying to switch over to Godot, they seem to be developing with an eye towards the kind of assets I'm actually going to use, instead of AAA super-high-res stuff.
- gentleman11 6y ago
- jonwinstanley 6y agoThanks for making this, I have never signed up to something so quickly before. I've tried to get started with Unity a few times before and have the exact issues described. I know how to program, just tell me how to do it in this IDE!
- headcanon 6y agoThanks for making this! I agree, there is a lot missing from Unity resources for experienced software engineers from other disciplines. Some things I would really like to figure out are some of the idiomatic ways monobehaviors are structured, the variability between them, how best to separate game logic from implementation specifics, and best practices for reusability in real life, beyond what most of the tutorials teach. Subscribed. Looking forward to seeing the next set of articles!
- Eyas 6y agoThank you! I'll bookmark this comment as I'm trying to take stock of what would be most helpful. There are two kind of opposing directions I see a need for: - "Beginner Unity" take tailored for an Engineer. E.g. let's talk about the input system, frame-rate independence, overview of rendering/lighting, a high level overview of the editor, etc. And get that out of the way. - Satisfying what I might call a thirst for idioms/best practices from a SWE perspective. E.g. separation of concerns in MonoBehaviors, using ScriptableObjects, etc. Also maybe overview of things like "Should I still use Git with Unity or look into Collaborate?" and the like. My current sense is that I'll end up toeing the line between these two. But, regardless of this specific series, I enjoy writing about best practices and software patterns in anything I'm working on, and Unity is no exception -- so stay tuned!
- headcanon 6y agoYes I think both of those directions would be very helpful. Appreciate it!