ME FIRST GAMES
games for me and you
The Control Flow of a program is the order in which the program's code executes.
As a competent programmer, you NEED to understand where you are in the Control Flow and where it can lead you.
📌 By default, your program will execute instructions in a linear order, executing each line of code after the next.
📌 This linear flow can be broken up using conditional statements and function calls.
📌 It's easy to represent the Control Flow of your program using a graph.
📌 If using GCC, you can use tools like Trucov to print the Control Flow of your program.
📌 The If-Statement and Switch-Statement will cause your Control Flow to branch.
📌 Loops will cause your Control Flow to go back to a previous node.
📌 Function calls will jump to an entirely separate part of your control flow.
✅ When you are writing lines of code, you are defining the Control Flow of your program.
✅ Where it can branch, loop, jump, break; essentially what it can do and where it can go.
✅ The cool thing about the Control Flow is that you don't have to understand the entire graph at once.
✅ The graph can be broken up or "encapsulated" into a single section.
✅ This makes it easier for us to understand; that's why we separate code into different functions and classes.
🎮 In Unity, you can think of the entire Control Flow as a huge massive graph.
🎮 But we only need to worry about the Control Flow in our own MonoBehaviors. ➡️ Follow @mefirstgames for more game dev tips.
➡️ Free Unity Tools: https://www.mefirstgames.com/hierarchy-comments.html
The Singleton design pattern keeps the instantiation of a class to a single instance. Controversial but convenient, Singletons are something you will most definitely encounter in your life as a developer.
👍Singletons are very quick to implement and can make accessing an object easy.
👍Better than static classes, they can leverage polymorphism, cache values, and have their instances swapped out.
👍They require low memory usage, low latency, and only need one initialization.
👍In Unity, it offers better performance then FindObjectOfType.
👎Controlling initialization order across Singletons can become messy very quickly.
👎Deviates from the single responsibility principle.
👎Promotes mass coupling to a single instance.
👎It can be difficult to refactor, especially if you need to change its behavior in a different context.
👎In Unity, it is difficult to track the lifecycle of the Singleton MonoBehavior.
👎It's not always easy to subclass and extend.
👎Easy to abuse with many singletons and have limited flexibility in your codebase.
✅Do I recommend Singletons? Well, it depends...
✅Is your project small? Do you have time constraints? Will your class change in the future, or will it most likely always behave the same? e.g. logging system.
✅Singletons are not the cleanest or most flexible system, but they are convenient and quick to implement.
✅In Unity, Singleton MonoBehaviors can swap instances depending on what scene or prefab is loaded.
🚀Beware overuse, understand the limitations, and use it at your own discretion.
➡️Follow @mefirstgames for more game dev tips.
➡️Free Unity Tools: https://www.mefirstgames.com/hierarchy-comments.html
Getting started, you'll need to download Steamworks API.
📌 Steamworks provides everything you need to create Steam Leaderboards, Stats, and Achievements.
📌 You can also set up the Steam leaderboards in the Steam dashboard, but Steamworks also empowers the game to create a leaderboard itself.
📌 Steam supports persistent leaderboards that are automatically ordered.
📌 Updating a leaderboard is as simple as uploading your own personal score.
📌 Each Steamwork title can create up to 10,000 leaderboards!
📌 A leaderboard has no cap on the number of players that can be entered.
📌 In Barrel Blast, I let the game will automatically create a leaderboard if it doesn't exist.
📌 This means I don't have to manually create a leaderboard for each of the 300 levels.
📌 I can instead, create a new level, play it, and a leaderboard for that level just magically appears 🧙♂️
📌 Downloading the leaderboard is straight forward. Provide the name, the range, and asynchronously retrieve entries for that leaderboard.
📌 Setting up the UI is the trickiest part of the whole process. Cheap tools exist in the Asset Store for displaying a leaderboard.
📌 To manually show the leaderboard, set up a new UI prefab, and write a controller that will spawn a row for each entry in the leaderboard.
📌 It can display information like ranking, name, score, and other user data attached to the score.
✅ Follow @mefirstgames
💻 FREE Dev Tools → https://www.mefirstgames.com/hierarchy-comments.html
📌 Any GameObject can be tagged as EditorOnly.
📌 EditorOnly GameObjects are automatically removed when you make a build of your game.
📌 This means you can have GameObjects that only exist when developing and debugging your game in the Unity Editor.
📌 EditorOnly is great if you want to draw a waypoint or path of an enemy in the Editor.
📌 It allows you to add debug visuals and markup data to your scene without worrying about any performance cost for your actual builds.
📌 When combined with Gizmos, EditorOnly adds to your ability to customize the Unity Editor to maximize your game development efficiency and potential.
✅Get FREE Unity Tools → https://www.mefirstgames.com/hierarchy-comments.html
As a professional game developer, you'll frequently find yourself working inside prefabs that are complicated or that were created by other people.
📌 Unity offers little to no support for documenting your prefabs. This is a huge deficiency when working in larger teams, where multiple people will touch a single prefab over a long duration of time.
📌 Some point out you can add documentation to external sources like a Google Doc. But this is inconvenient, easy to forget, and error-prone for updating.
📌 Imagine NOT being able to comment your code in the file, but instead having to add every comment to a Google Doc instead. This would be a disaster.
📌 The best documentation is in the code. And the best documentation is in the prefab.
📌 So how do we do this and how do we do it without a performance cost?
📌 I've created an editor script that allows you to comment directly inside your prefab or scene.
📌 Anything starting with the prefix "//" will automatically highlight as green, giving you a visual line break.
📌 Don't worry about performance, because these comments are automatically tagged as EditorOnly. This means Unity will strip these game objects out of builds.
📌 There are other Unity tools that do this, but they always add ugly backgrounds and messy color schemes. My tool is lightweight, performant, and allows you to easily document your prefabs and scenes without any fuss.
📌 Documentation standards do apply, and you want to make sure your comments are short, clean, and convey useful information.
📌 Simple, straight forward, and performant, I hope this tool helps your development process in small and large teams.
Download Free Here
Input is an essential part of your game.
📌 Unity just made the Input System a verified package.
📌 The Legacy Input system has always been a pain. With a convoluted setup, developers could find themselves copying input code everywhere when their design wasn't well planned.
📌 Players can now define a series of input actions inside an ActionMap. Individual ActionMaps may be used to control the player, a vehicle, or specialized UI views.
📌 Individual Actions may be mapped to specific input bindings from different devices. This abstracts away the details of what the input binding is firing. Now your game can just check the actions.
📌 Schemes represent different control setups. This is good for device types, like Keyboard&Mouse vs Gamepad.
📌 Your Input settings can easily be exported into an auto-generated C# file. This gives you access to the polling or subscribing to the actions for any given ActionMap.
⭐️ The addition of the Input System was long overdue. The ease of use and modular design of the new system allows you to focus on what really matters, your game.
Meet STU 😈
✅ Potential Game Name: STU - Adventure of Bit
💻 Hi everyone! This is a fantastic clip of the new game I'm working on. Currently in the experimental design and pre-alpha stages. I'm targeting a short story-driven game with unique characters in the digital world.
STU stands for
* Self Aware
* Turing Complete
* Universal Program
🎮 STU is the first truly self-aware artificial intelligence every created. Vast and comprehension, STU's system extend multiple machines across the web. Currently, in conflict with humans, STU creates Bit to assist with the humans.
😈 STU may come off rude and condescending, but STU does not do so intentionally. STU views Bit and humans as inferior, similar to how humans may view a colony of ants. The fact they work together and create amazing colonies is impressive, but when push comes to shove, they can only affect us as a pest.
Unity and other modern game engines offer built-in physics support. Unity specifically, empowers you with colliders and rigidbodies. These simulate physics but also give you the ability to manipulate and apply your own forces.
📌 Rigidbody.AddForce applies a force to any dynamic rigidbody.
📌 The ForceMode passed in allows you to control the type of force given.
📌 ForceMode.Force: Add a continuous force to the rigidbody, using its mass. I like using this for mechanics that push or pull over time, and larger (more massive) rigidbodies are harder to push.
📌 ForceMode.Acceleration: Add a continuous acceleration to the rigidbody, ignoring its mass. This is good for mechanics that push or pull rigidbodies of any size at the same rate.
📌 ForceMode.Impulse: Add an instant force impulse to the rigidbody, using its mass. Use this for pushing the character, where a short burst of force occurs, knocking back you back.
📌 ForceMode.VelocityChange: Add an instant velocity change to the rigidbody, ignoring its mass. I personally enjoy using this inside a character's movement controller. It gives you granular control over a character's velocity and movement while still working within the physics system.
📌 Rigidbody.AddForceAtPosition applies a force at a given position. This can make your explosions even more realistic because torque will be applied at the same time. Watch boxes tumble and fly away.
📌 Rigidbody.AddRelativeForce applies a force relative to the rigidbodies rotation. It's important to not confuse the transform rotation with the rigidbody rotation, which may be updated less frequently than the transform rotation.
💬 Did I miss something? Leave a comment down below ⬇️
Enabling IL2CPP on your Unity builds will significantly boost your performance and help you transform your game into something truly great.
📌 When building a project using IL2CPP, Unity converts IL code from scripts and assemblies to C++, before creating a native binary file (.exe, apk, .xap, for example) for your chosen platform. Some of the uses for IL2CPP include increasing the performance, security, and platform compatibility of your Unity projects.
📌 This is different from the old Mono implementation that uses JIT (just in time) compilation.
📌 Compiling C++ to a native binary is a huge performance advantage from Mono JIT.
📌 There is no warm-up the first time you call a method with IL2CPP. Everything is compiled when the native binary is created.
📌 IL2CPP will cause your binary to be larger, but you can enable code stripping to help mitigate this issue.
📌 Build times with IL2CPP are longer than Mono, however in most cases, it is well worth it when creating a build people will play.
📌 Unity Editor still runs Mono. This is a good thing because it takes less time to recompile your scripts and in most cases, your computer is more powerful than the devices it will run on.
📌 IL2CPP is now a requirement for iOS and is the default for Android builds.
📌 IL2CPP relies on C++ compilers not implemented by Unity. This is a very good thing. Modern C++ compilers very stable and are great at compiler time optimizations.
📌 Reflection in C# causes IL2CPP to generate "metadata" embedded in C++ so that "reflection" can occur in the C++ code. This increases code size and may even lead to the embarrassing "too much code" issue Unity suffers from on mobile platforms.
Here are some super basic tips to increase your game's performance in Unity
📌 Only run code when things change. Instead of constantly polling and checking a state inside Update, try using Events and Actions to trigger code when something changes.
📌 If polling is required, then try only running your code every N frames or after a delay. Your AI code probably does not need to fire every frame.
📌 Move code out of loops when they can be run once, before, or after.
📌 Cache references and values instead of calculating them every time. GetComponent is included.
📌 Pool objects instead of Instantiating everything. Keep GameObjects in a list and when they are no longer needed, disable them. Enable them later as needed.
📌 Never use SendMessage and Camera.main. They are slow.
📌 Do not use FindObjectOfType. Instead, serialize a reference and link it in the Editor. Alternatively, you can create a singleton and use the reference directly.
📌 Avoid Vector3.Distance and Vector2.Magnitude because they use square root calculations. When possible, use Vector3.sqrMagnitude.
📌 Manually call System.GC.Collect() during loading screens or scene transitions.
📌 If you're getting large CPU spikes from garbage collection, then try incremental garbage collection.
📌 Disable/Enable MeshRenderer's using MeshRenderers.enabled. There is overhead activating and deactivating GameObject's with SetActive.
📌 Avoid calling DestroyImmediate.
📌 Store settings inside of ScriptableObjects instead of Prefabs. This avoids redundant variables allocated for prefabs using the same settings.
Me First Games is an independent game studio dedicated to creating unique and bizarre video games.
Star Impact is an upcoming adventure platformer coming to PC, Mac, and Linux.
Copyright (c) 2020 Me First LLC