{"id":56,"date":"2021-10-24T07:32:47","date_gmt":"2021-10-24T07:32:47","guid":{"rendered":"https:\/\/docs.sisus.co\/inity\/?p=56"},"modified":"2025-07-14T19:40:28","modified_gmt":"2025-07-14T19:40:28","slug":"scriptableobject-t","status":"publish","type":"post","link":"https:\/\/docs.sisus.co\/init-args\/clients\/scriptableobject-t\/","title":{"rendered":"2. ScriptableObject&lt;T&#8230;&gt;"},"content":{"rendered":"<p>Init(args) contains new generic versions of the ScriptableObject base class, extending it with the ability to specify upto six objects that the class depends on.<\/p>\n<p>For example the following GameEvent class depends on a string and a GameObject.<\/p>\n<pre class=\"western\"><span style=\"color: #000000;\"><span style=\"color: #800000;\"><b>public<\/b><\/span> <span style=\"color: #800000;\"><b>class<\/b><\/span> GameEvent <span style=\"color: #808030;\">:<\/span> ScriptableObject<span style=\"color: #808030;\">&lt;<\/span><span style=\"color: #800000;\"><b>string<\/b><\/span><span style=\"color: #808030;\">,<\/span> GameObject<span style=\"color: #808030;\">&gt;<\/span><\/span><\/pre>\n<p>When you create a class that inherits from one of the generic ScriptableObject base classes, you\u2019ll always also need to implement the <b>Init<\/b> function for receiving the arguments.<\/p>\n<pre class=\"western\"><span style=\"color: #000000;\"><span style=\"color: #800000;\"><b>protected<\/b><\/span> <span style=\"color: #800000;\"><b>override<\/b><\/span> <span style=\"color: #800000;\"><b>void<\/b><\/span> Init<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\"><b>string<\/b><\/span> id<span style=\"color: #808030;\">,<\/span> GameObject target<span style=\"color: #808030;\">)<\/span><\/span>\r\n<span style=\"color: #800080;\">{<\/span>\r\n<span style=\"color: #000000;\">   Id <span style=\"color: #808030;\">=<\/span> id<span style=\"color: #800080;\">;<\/span><\/span>\r\n<span style=\"color: #000000;\">   Target <span style=\"color: #808030;\">=<\/span> target<span style=\"color: #800080;\">;<\/span><\/span>\r\n<span style=\"color: #800080;\">}<\/span><\/pre>\n<p>The Init function is called when the object is being initialized, before the Awake function.<\/p>\n<h2 class=\"western\"><span style=\"font-family: Liberation Sans, sans-serif;\"><span style=\"font-size: x-large;\"><b>Creating Instances<\/b><\/span><\/span><\/h2>\n<p>If you have a ScriptableObject of type TScriptableObject that inherits from ScriptableObject&lt;TArgument&gt;, you can create a new instance of the class and initialize it with an argument using the following syntax:<\/p>\n<pre class=\"western\"><span style=\"color: #000000;\">Create<span style=\"color: #808030;\">.<\/span>Instance<span style=\"color: #808030;\">&lt;<\/span>TScriptableObject<span style=\"color: #808030;\">,<\/span> T<span style=\"font-family: Liberation Mono, monospace;\"><span style=\"font-size: small;\">A<\/span><\/span>rgument<span style=\"color: #808030;\">&gt;(<\/span>argument<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span><\/span><\/pre>\n<p>You can create a clone of an existing instance using the following syntax:<\/p>\n<pre class=\"western\"><span style=\"color: #000000;\">sciptableObject<span style=\"color: #808030;\">.<\/span>Instantiate<span style=\"color: #808030;\">(<\/span>argument<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span><\/span><\/pre>\n<h2 class=\"western\"><span style=\"color: #000000;\"><span style=\"font-family: Liberation Sans, sans-serif;\"><span style=\"font-size: x-large;\"><b>Awake Event<\/b><\/span><\/span><\/span><\/h2>\n<p><span style=\"color: #000000;\">Do not add an Awake function to classes that inherit from one of the generic ScriptableObject classes, because the classes already define an Awake function. If you need to do something during the Awake event, override the OnAwake function instead.<\/span><\/p>\n<h2 class=\"western\"><span style=\"color: #000000;\"><span style=\"font-family: Liberation Sans, sans-serif;\"><span style=\"font-size: x-large;\"><b>Reset Event<\/b><\/span><\/span><\/span><\/h2>\n<p><span style=\"color: #800080;\"><span style=\"color: #000000;\">Do not add a Reset function to classes that inherit from one of the generic <\/span><span style=\"color: #000000;\">ScriptableObject<\/span><span style=\"color: #000000;\"> classes, because the classes already define a Reset function. If you need to do something during the Reset event, override the OnReset function instead.<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Init(args) contains new generic versions of the ScriptableObject base class, extending it with the ability to specify upto six objects that the class depends on. For example the following GameEvent class depends on a string and a GameObject. public class GameEvent : ScriptableObject&lt;string, GameObject&gt; When you create a class that inherits from one of the ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/docs.sisus.co\/init-args\/clients\/scriptableobject-t\/\" 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":[10],"tags":[],"_links":{"self":[{"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/posts\/56"}],"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=56"}],"version-history":[{"count":7,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/posts\/56\/revisions"}],"predecessor-version":[{"id":599,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/posts\/56\/revisions\/599"}],"wp:attachment":[{"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/media?parent=56"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/categories?post=56"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.sisus.co\/init-args\/wp-json\/wp\/v2\/tags?post=56"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}