{"id":13,"date":"2021-07-19T15:58:06","date_gmt":"2021-07-19T15:58:06","guid":{"rendered":"https:\/\/docs.sisus.co\/inity\/?p=13"},"modified":"2025-07-27T13:53:33","modified_gmt":"2025-07-27T13:53:33","slug":"what-is-init-args","status":"publish","type":"post","link":"https:\/\/docs.sisus.co\/init-args\/introduction\/what-is-init-args\/","title":{"rendered":"1. What Is Init(args)"},"content":{"rendered":"<p><img loading=\"lazy\" class=\" wp-image-916 aligncenter\" src=\"https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2021\/07\/init-args-di.png\" alt=\"\" width=\"512\" height=\"512\" srcset=\"https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2021\/07\/init-args-di.png 512w, https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2021\/07\/init-args-di-300x300.png 300w, https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2021\/07\/init-args-di-150x150.png 150w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><\/p>\n<p><strong>Init(args)<\/strong> is a straightforward and type-safe solution for providing your components with all the objects that they depend on.<\/p>\n<p>Here are some reasons why Init(args) could be the ideal choice to power the architecture of your next game&#8230;<\/p>\n<h1>It&#8217;s Simple<\/h1>\n<p>Init(args)&#8217;s <strong>Inspector<\/strong> and <strong>attribute<\/strong>-based workflow is incredibly intuitive &#8211; the basics can literally be learned in a matter of <strong>minutes<\/strong>.<\/p>\n<pre>[Service(FindFromScene = true)] \/\/ &lt;- Register a service\r\nclass Player : MonoBehaviour { ... }\r\n\r\nclass Enemy : MonoBehaviour&lt;Player&gt;\r\n{\r\n   protected override void Init(Player player) { ... } \/\/ &lt;- Receive the service\r\n}<\/pre>\n<p>Thanks to this all developers in your team can use Init(args) to connect objects together \u2013 no software engineering degree required.<\/p>\n<h1>It&#8217;s Inspector-Integrated<\/h1>\n<p>Services that clients will receive are visualized in the Inspector and support click-to-ping &#8211; just like you&#8217;re used to with serialized fields!<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-955\" src=\"https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2021\/07\/pingable.png\" alt=\"\" width=\"484\" height=\"262\" srcset=\"https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2021\/07\/pingable.png 484w, https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2021\/07\/pingable-300x162.png 300w\" sizes=\"(max-width: 484px) 100vw, 484px\" \/><\/p>\n<h1>It&#8217;s Dependable<\/h1>\n<p>Clients <em>always<\/em> receive the services they depend on before their Awake event &#8211; regardless of whether they&#8217;re loaded as part of a <strong>scene<\/strong>, instantiated from a <strong>prefab<\/strong>, or created using <strong>AddComponent<\/strong>.<\/p>\n<pre>class Enemy : MonoBehaviour&lt;Player&gt;\r\n{\r\n   Player player;\r\n\r\n   protected override void Init(Player player) =&gt; this.player = player;\r\n\r\n   protected override void OnAwake() =&gt; Debug.Log($\"Player: {player.name}\"); \/\/ &lt;- this is safe\r\n}<\/pre>\n<h1>It&#8217;s Debuggable<\/h1>\n<p>Forgot to register a service that is required by a client?<\/p>\n<p>Init(args) will display a warning in the Inspector and log a warning in Edit Mode, and throw an exception and visualize unserialized fields in the Inspector in Play Mode.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-958\" src=\"https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2021\/07\/missing-int-argument-warning.png\" alt=\"\" width=\"444\" height=\"68\" srcset=\"https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2021\/07\/missing-int-argument-warning.png 444w, https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2021\/07\/missing-int-argument-warning-300x46.png 300w\" sizes=\"(max-width: 444px) 100vw, 444px\" \/>\u00a0 <img loading=\"lazy\" class=\"alignnone size-full wp-image-956\" src=\"https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2021\/07\/runtime-state-1.png\" alt=\"\" width=\"409\" height=\"174\" srcset=\"https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2021\/07\/runtime-state-1.png 409w, https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2021\/07\/runtime-state-1-300x128.png 300w\" sizes=\"(max-width: 409px) 100vw, 409px\" \/><\/p>\n<h1>It&#8217;s Highly Flexible<\/h1>\n<p>Global and local services, full interface support, cross-scene references, value providers&#8230; don&#8217;t let Init(args)&#8217;s ease-of-use mislead you into thinking it&#8217;s lacking in the power department!<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-974\" src=\"https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2021\/07\/initializer.png\" alt=\"\" width=\"425\" height=\"201\" srcset=\"https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2021\/07\/initializer.png 425w, https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2021\/07\/initializer-300x142.png 300w\" sizes=\"(max-width: 425px) 100vw, 425px\" \/><\/p>\n<h1>It&#8217;s Fast<\/h1>\n<p>The simple and type-safe injection pipelines at the heart of Init(args) don&#8217;t depend on reflection, IL post-processing or source generators, while delivering class-leading performance.<\/p>\n<table style=\"height: 233px;\" width=\"637\">\n<tbody>\n<tr>\n<td><strong>Tested<\/strong><\/td>\n<td><strong>Average (ns)<\/strong><\/td>\n<td><strong>Details<\/strong><\/td>\n<\/tr>\n<tr>\n<td><strong>Init(args)<\/strong><\/td>\n<td><strong>3.053<\/strong><\/td>\n<td><strong>via MonoBehaviour&lt;T&gt;<\/strong><\/td>\n<\/tr>\n<tr>\n<td>VContainer<\/td>\n<td>3.343<\/td>\n<td>via InjectGameObject, Source Generator: On<\/td>\n<\/tr>\n<tr>\n<td>Reflex<\/td>\n<td>3.757<\/td>\n<td>via GameObjectSelfInjector<\/td>\n<\/tr>\n<tr>\n<td>[SerializeReference]<\/td>\n<td>8.312<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>Extenject<\/td>\n<td>8.718<\/td>\n<td>via ZenAutoInjecter, Reflection Baking: Off<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Main Features<\/h2>\n<ol>\n<li><a href=\"https:\/\/docs.sisus.co\/init-args\/reference\/global-services\/\"><strong>Global Services<\/strong><\/a> &#8211; simply add the [Service] attribute to create a global service.<\/li>\n<li><a href=\"https:\/\/docs.sisus.co\/init-args\/reference\/local-services\/\"><strong>Local Services<\/strong><\/a> &#8211; simply use the context menu in the Inspector Window to create a local service.<\/li>\n<li><a href=\"https:\/\/docs.sisus.co\/init-args\/initializers\/initializer\/\"><strong>Full Interface Support<\/strong><\/a> &#8211; assign components, scriptable objects and plain C# objects into the same interface fields.<\/li>\n<li><a href=\"https:\/\/docs.sisus.co\/init-args\/initializers\/cross-scene-references\/\"><strong>Cross-Scene References<\/strong><\/a> &#8211; just drag-and-drop an Object reference from one scene to another.<\/li>\n<li><a href=\"https:\/\/docs.sisus.co\/init-args\/initializers\/prefab-instance-references\/\"><strong>Prefab Instance References<\/strong><\/a> &#8211; just drag-and-drop a prefab asset and pick &#8216;Prefab Instance&#8217;.<\/li>\n<li><a href=\"https:\/\/docs.sisus.co\/init-args\/initializers\/value-providers\/\"><strong>Value Providers<\/strong><\/a> &#8211; localized strings, randomized values, addressable assets&#8230;<\/li>\n<li><a href=\"https:\/\/docs.sisus.co\/init-args\/wrappers\/wrapper\/\"><strong>Wrappers<\/strong><\/a> &#8211; attach plain old C# objects to GameObjects and make unit testing a breeze.<\/li>\n<li><a href=\"https:\/\/docs.sisus.co\/init-args\/getting-started\/initializing-components-in-code\/\"><strong>Instantiate with arguments<\/strong><\/a> &#8211; pass arguments when instantiating an Object.<\/li>\n<li><a href=\"https:\/\/docs.sisus.co\/init-args\/getting-started\/initializing-components-in-code\/\"><strong>Add Component with arguments<\/strong><\/a> &#8211; pass arguments when attaching a component to a GameObject.<\/li>\n<li><a href=\"https:\/\/docs.sisus.co\/init-args\/clients\/scriptableobject-t\/\"><strong>Create ScriptableObject with arguments<\/strong><\/a> &#8211; pass arguments when creating a ScriptableObject.<\/li>\n<li><a href=\"https:\/\/docs.sisus.co\/init-args\/getting-started\/initializing-components-in-code\/\"><strong>new GameObject with arguments<\/strong><\/a> &#8211; create a new GameObject and initialize its components.<\/li>\n<li><a href=\"https:\/\/docs.sisus.co\/init-args\/introduction\/comparison\/\"><strong>Type-safe and reflection-free injection<\/strong><\/a><\/li>\n<li><a href=\"https:\/\/docs.sisus.co\/init-args\/services\/service-attribute\/\"><strong>Asynchronous Initialization Support<\/strong><\/a> &#8211; Want to load services from Addressables to avoid stuttering? Init(args) has got you covered.<\/li>\n<li><a href=\"https:\/\/docs.sisus.co\/init-args\/clients\/monobehaviour-t\/\"><strong>Deferred Initialization Support<\/strong><\/a> &#8211; A service is not ready yet when a client is being loaded? Init(args) can automatically delay its initialization!<\/li>\n<\/ol>\n<p>Let Init(args) take care of all the dirty plumbing work, and allow yourself to fully focus on just creating a great game!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Init(args) is a straightforward and type-safe solution for providing your components with all the objects that they depend on. Here are some reasons why Init(args) could be the ideal choice to power the architecture of your next game&#8230; It&#8217;s Simple Init(args)&#8217;s Inspector and attribute-based workflow is incredibly intuitive &#8211; the basics can literally be learned ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/docs.sisus.co\/init-args\/introduction\/what-is-init-args\/\" title=\"read more\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/posts\/13"}],"collection":[{"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/comments?post=13"}],"version-history":[{"count":52,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/posts\/13\/revisions"}],"predecessor-version":[{"id":985,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/posts\/13\/revisions\/985"}],"wp:attachment":[{"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/media?parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/categories?post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/tags?post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}