{"id":86,"date":"2021-10-24T07:58:48","date_gmt":"2021-10-24T07:58:48","guid":{"rendered":"https:\/\/docs.sisus.co\/inity\/?p=86"},"modified":"2025-07-14T19:41:17","modified_gmt":"2025-07-14T19:41:17","slug":"iargs","status":"publish","type":"post","link":"https:\/\/docs.sisus.co\/init-args\/reference\/iargs\/","title":{"rendered":"IArgs&lt;T&#8230;&gt;"},"content":{"rendered":"<p>Classes that implement one of the generic IArgs&lt;T\u2026&gt; interfaces can be provided with arguments during initialization (up to a maximum of twelve).<\/p>\n<p>Methods such as Instantiate&lt;TObject, T&#8230;&gt; and AddComponent&lt;TComponent, T&#8230;&gt; can only be used to create instances of classes that implement one of the IArgs&lt;T&#8230;&gt; interfaces.<\/p>\n<h3>A contract to receive arguments<\/h3>\n<p>Any object that implements an IArgs&lt;T\u2026&gt; interface makes a promise to receive arguments that have been injected for them during their initialization process using the <a href=\"https:\/\/docs.sisus.co\/init-args\/features\/initargs\/\">InitArgs.TryGet<\/a> method.<\/p>\n<p>It is recommended that components retrieve initialization arguments that have been provided to them during their <a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/MonoBehaviour.Awake.html\">Awake<\/a> event in most cases. The Awake event has the benefit of always only being executed once, and occurring on the main thread after the deserialization process has already finished.<\/p>\n<p>The <a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/MonoBehaviour.OnEnable.html\">OnEnable<\/a> event is another viable option, in cases where you want components to reacquire their dependencies every time they become active and enabled.<\/p>\n<p>It is also possible to retrieve <a href=\"https:\/\/docs.sisus.co\/init-args\/reference\/global-services\/\">global services<\/a> registered using the <a href=\"https:\/\/docs.sisus.co\/init-args\/services\/service-attribute\/\">[Service] attribute<\/a>, or manually via <a href=\"https:\/\/docs.sisus.co\/init-args\/reference\/service-api\/\">Service.Set<\/a>, in a a parameterless constructor or <a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/ISerializationCallbackReceiver.OnAfterDeserialize.html\">OnAfterDeserialize<\/a> method if you pass <em>Context.Constructor<\/em> or <em>Context.OnAfterDeserialize<\/em> to the InitArgs.TryGet method. However it is important to understand that these can get executed on background threads, and the constructor gets called before the deserialization process occurs, which means that if you were to assign initialization arguments into any serialized fields, they could get overridden during the deserialization process.<\/p>\n<p>The <a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/MonoBehaviour.Start.html\">Start<\/a> event function is not considered to be part of the initialization process, as it only only gets executed after a slight delay.<\/p>\n<p>If an Object that implements IArgs&lt;T&#8230;&gt; but does not receive the arguments that were passed to it, then an InitArgumentsNotReceivedException typically gets thrown. However, if the Object implements IInitializable&lt;T&#8230;&gt; the arguments can be injected through the Init method, even if the client fails to receive the arguments independently, and in this case no exception will be thrown.<\/p>\n<blockquote><p><strong>Note<\/strong>: The Awake event function does not get called for components on <a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/GameObject-activeSelf.html\">inactive GameObjects<\/a>. Because of this it is advisable for component classes to implement <a href=\"https:\/\/docs.sisus.co\/init-args\/uncategorized\/iinitializable\/\">IInitializable&lt;T\u2026&gt;<\/a> and not just IArgs&lt;T&#8230;&gt; in most cases.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Classes that implement one of the generic IArgs&lt;T\u2026&gt; interfaces can be provided with arguments during initialization (up to a maximum of twelve). Methods such as Instantiate&lt;TObject, T&#8230;&gt; and AddComponent&lt;TComponent, T&#8230;&gt; can only be used to create instances of classes that implement one of the IArgs&lt;T&#8230;&gt; interfaces. A contract to receive arguments Any object that implements ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/docs.sisus.co\/init-args\/reference\/iargs\/\" 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":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/posts\/86"}],"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=86"}],"version-history":[{"count":14,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/posts\/86\/revisions"}],"predecessor-version":[{"id":818,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/posts\/86\/revisions\/818"}],"wp:attachment":[{"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/media?parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/categories?post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/tags?post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}