{"id":843,"date":"2025-07-24T06:09:44","date_gmt":"2025-07-24T06:09:44","guid":{"rendered":"https:\/\/docs.sisus.co\/init-args\/?p=843"},"modified":"2025-07-25T06:41:02","modified_gmt":"2025-07-25T06:41:02","slug":"prefab-instance-references","status":"publish","type":"post","link":"https:\/\/docs.sisus.co\/init-args\/initializers\/prefab-instance-references\/","title":{"rendered":"6. Prefab Instance References"},"content":{"rendered":"<p>References to GameObjects and components that are only instantiated at runtime\u00a0can be assigned into Init fields of <a href=\"https:\/\/docs.sisus.co\/init-args\/clients\/monobehaviour-t\/\">client components<\/a> that have an <a href=\"https:\/\/docs.sisus.co\/init-args\/initializers\/initializer\/\">initializer<\/a>.<\/p>\n<p>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 &#8216;Prefab Instance&#8217; from the dropdown that opens.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-844\" src=\"https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2025\/07\/prefab-instance-references.gif\" alt=\"\" width=\"618\" height=\"190\" \/><\/p>\n<p>This will make Init(args) automatically generate a unique <strong>Cross-Scene Id<\/strong> for the dragged Object, and assign a value provider into the client&#8217;s Init field, which will be used to automatically resolve the prefab instance reference at runtime during initialization.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-847\" src=\"https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2025\/07\/prefab-instance-reference-tooltip.png\" alt=\"\" width=\"412\" height=\"181\" srcset=\"https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2025\/07\/prefab-instance-reference-tooltip.png 412w, https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2025\/07\/prefab-instance-reference-tooltip-300x132.png 300w\" sizes=\"(max-width: 412px) 100vw, 412px\" \/><\/p>\n<p>You can click the Object field to ping the prefab asset from which the prefab instance will be created at runtime.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-846\" src=\"https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2025\/07\/ping-prefab-instance-reference-asset.gif\" alt=\"\" width=\"618\" height=\"162\" \/><\/p>\n<p>You can also right-click the prefab icon shown next to the field to open a context menu containing various functionality, such as opening the prefab asset, or copying the Cross-Scene Id of the referenced prefab instance to your clipboard.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-848\" src=\"https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2025\/07\/prefab-instance-reference-context-menu.png\" alt=\"\" width=\"412\" height=\"141\" srcset=\"https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2025\/07\/prefab-instance-reference-context-menu.png 412w, https:\/\/docs.sisus.co\/init-args\/wp-content\/uploads\/sites\/6\/2025\/07\/prefab-instance-reference-context-menu-300x103.png 300w\" sizes=\"(max-width: 412px) 100vw, 412px\" \/><\/p>\n<h2>Asynchronous Initialization<\/h2>\n<p>At runtime, if you want the client to receive the prefab instance in its Init method immediately when the client&#8217;s scene is loaded, you have to make sure to instantiate the prefab before the client&#8217;s scene finishes loading.<\/p>\n<p>If the client is loaded before the prefab is instantiated, the client component will automatically be disabled and its initialization delayed, until the moment that the prefab instance becomes available (see <a href=\"https:\/\/docs.sisus.co\/init-args\/clients\/monobehaviour-t\/\">MonoBehaviour&lt;T&gt;&#8217;s Asynchronous Initialization section<\/a> for more details).<\/p>\n<h3>Any&lt;TValue&gt;<\/h3>\n<p><a href=\"https:\/\/docs.sisus.co\/init-args\/reference\/any-t\/\">Any&lt;TValue&gt;<\/a> type fields can also be used to support prefab instance references in addition to initializers.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>References to GameObjects and components that are only instantiated at runtime\u00a0can 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 &#8216;Prefab Instance&#8217; ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/docs.sisus.co\/init-args\/initializers\/prefab-instance-references\/\" 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":[12],"tags":[],"_links":{"self":[{"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/posts\/843"}],"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=843"}],"version-history":[{"count":6,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/posts\/843\/revisions"}],"predecessor-version":[{"id":860,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/posts\/843\/revisions\/860"}],"wp:attachment":[{"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/media?parent=843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/categories?post=843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/tags?post=843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}