03. InitArgs

  05. Reference No Comments

The InitArgs class is the bridge through which initialization arguments are passed from the classes that create instances to the objects that are being created (called clients).

Note that in most cases you don’t need to use InitArgs directly; all of the various methods provided for initializing instances with arguments already handle this for you behind the scenes. But for those less common scenarios where you want to write your own code that makes use of the InitArgs you can find details about its inner workings below.


The InitArgs.Set method can be used to store one to six arguments for a client of a specific type, which the client can subsequently receive during its initialization.

The client class must implement an IArgs<T…> interface with generic argument types matching the types of the parameters being passed in order for it to be targetable by the InitArgs.Set method.

InitArgs.Set<TClient, TArgument>(argument);

The generic TClient type does not have to be the exact type of the client but can also be its base class.


The InitArgs.TryGet method can be used by a client object to retrieve arguments stored in InitArgs during its initialization phase.

if(InitArgs.TryGet(Context.Awake, this, out TArgument argument))

Use the Context argument to specify the method context from which InitArgs is being called, for example Context.Awake when calling during the Awake event or Context.Reset when calling during the Reset event.


Use InitArgs.Clear to remove arguments cached in InitArgs. This should usually be called by the class responsible for providing the arguments to the client after initialization.


Use this method to determine whether or not Init arguments provided for a client have been received yet or not.

This can be useful for throwing an exception if the client object has failed to receive the arguments during its initialization phase.

Leave a Reply

Your email address will not be published. Required fields are marked *