What Are Optional Init Arguments? By default Init(args) assumes that every Init argument a client receives is required. If an argument is missing, and the Null Argument Guard is enabled, you get warnings shown in the Inspector, logged to the Console in Edit Mode and exceptions thrown at runtime. Sometimes, however, you might want to ..
Author : Timo Naskali
Testable By Default Because clients receive all their dependencies from the outside, instead of fetching them from singletons or using methods like GetComponent and FindAnyObjectByType, it is easy to swap out any of them with test doubles during unit tests. There’s no need to create test scenes or prefabs and configure them using the Inspector. ..
The Init(args) package comes bundled with the init-args skill, which teaches an AI agent how to use Init(args) effectively. The skill comes in several variants, optimized for different AI agents: Assistant: com.sisus.init-args/AIAssistantSkills/init-args Claude: com.sisus.init-args/.claude/skills/init-args Cursor, Codex: com.sisus.init-args/.agents/skills/init-args If you use Unity AI Assistant, you’ll need to allow the skill’s usage under Preferences > AI > Skills ..
Init(args) can automatically optimize the order in which components that are loaded as part of the same scene or prefab are initialized, based on their dependencies. Why Init Order Matters Imagine you have a component called Client which needs to execute a method on another component called Service when it’s being enabled: class Client : ..
Dynamically Loaded Assemblies Init(args) supports creating global services registered using the [Service] attribute from assemblies that are loaded at runtime. If the assembly is loaded before Init(args) has finished initializing global services, then global services registered in the assembly using the [Service] attribute will get initialized as part of the initial service registration process. This ..
Global Services Typically you can register a global service simply by adding the [Service] attribute directly to type of the service: [Service] public class SomeService { } Sometimes, however, you might want to create services from types defined inside third-party assets, in which case making any modifications to their source code could be out of ..
Init(args) comes bundled with several add-ons. They can all be found under Packages/Init(args)/Add-Ons in the Project window and installed by double-clicking their respective unity packages and selecting Import. Odin Contains SerializedMonoBehaviour<T…> base classes. Enables you to create components that are serialized by the Odin serializer like SerializedMonoBehaviour, and can automatically receive services during initialization like ..
The Preload Scene (also known as the Boostrap Scene) is a technique where you always launch your game from the same scene. This enables you, among other things, to place important global services into this scene, and ensure that they are always loaded before any other scene objects in the game. One big pain point ..
Null Argument Guard The Null Argument Guard is a feature that can automatically inform you about missing Init arguments that any of your components might have. The feature consists of three distinct parts: Inspector Warnings – Warnings shown in the Editor when you view a component containing missing Init arguments in the Inspector Window. Edit ..
References to GameObjects and components that are only instantiated at runtime can be assigned into Init fields of client components that have an initializer. To assign a reference to an yet-to-be-instantiated prefab instance, drag-and-drop a prefab asset from the Project window into the Init field of a client component in a scene, and select ‘Prefab Instance’ ..