Init(args)
What Is Init(args)?
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…
✅ It’s Simple
Init(args)'s Inspector and attribute-based workflow is incredibly intuitive – the basics can literally be learned in a matter of minutes.
✅ It’s Inspector-Integrated
Services that clients will receive are visualized in the Inspector and support click-to-ping – just like you’re used to with serialized fields!
✅ It’s Dependable
Clients always receive the services they depend on before their Awake event – regardless of whether they’re loaded as part of a scene, instantiated from a prefab, or created using AddComponent.
✅ It’s Debuggable
Forgot to register a service that is required by a client?
Init(args) will guide you to resolve the issue with Inspector help boxes and Console messages.
In Play Mode you can see unserialized state in the Inspector so you can easily spot unreceived services.
And should everything else fail, there's even a Debugger window.
✅ It’s Highly Flexible
Global and local services, full interface support, cross-scene references, value providers… don’t let Init(args)’s ease-of-use mislead you into thinking it’s lacking in the power department!
✅ It’s Fast!
The simple and type-safe injection pipelines at the heart of Init(args) don’t depend on reflection, IL post-processing or source generators, while delivering class-leading performance.
Main Features
Let Init(args) take care of all the dirty plumbing work, and allow yourself to fully focus on just creating a great game!
Also Included: A demo scene contaning an example game!
Links
• Forum - Have any questions or ideas for new features? Discuss here.
• Documentation - Online Documentation for Init(args).
• Scripting Reference - Descriptions of all classes and class members in Init(args).
Release Notes
Version 1.5.6
- Added BaseClassGenerator for easile auto-generating new generic base classes (like MonoBehaviour<T...> from any base type.
- Pre-load scene now supports build indexes other than 0. This makes it possible to make the first scene in builds be blank or only contain a splash screen and only load the pre-load scene after that. This also makes it better compatible with Advanced Scene Manager.
- Cross-scene references can now be assigned into fields in prefab and ScriptableObject assets. The cross-scene references are automatically converted into sub-assets serializable by Unity.
- Extended CrossSceneReference public API to make it possible to load the scene containing the reference.
- Updated all base classes in Add-On packages.
- Added Any.TryGetValueProvider<TValueProvider>, to allow accessing the value provider assigned to an Any field.
- Fixed compile error in specific older versions of Unity 6.2.
- Fixed issue with ScriptableObject<T...> assets not reliably receiving global services in the Editor when entering Play Mode unless they had an Initializer attached.
- Fixed issue with "Make Service Of Type..." context menu item not marking the scene as having unsaved changes.
- Init section will now once again show separate warning boxes about issues that warrant one, such as hiding the Awake method.
- Fixed duplicate visualization of serialized state of wrapped object in Wrapper's Editor.
- Renamed AnyGeneric<T> to AnyValue<T>, given that Any<T> can handle generic types since Unity 2023.1, and it's only (most) value types which aren't supported.
- Init section now reacts to a component's class having [Init(WaitForServices = true)] by informing that it will wait for all the services, and not warning about any of them being missing in Edit Mode.
- Fixed potential exception occurring during initialization of global services which are also wrappers.
- Fixed warning CS4014 from CrossSceneReference.cs.
- Fixed issue where clients could fail to receive services registered using [Service(LoadScene = "...")] if both the client and the service belonged to the same scene and LoadAsync was not set to true.
- Fixed issue where a MissingReferenceException could get thrown when entering Play Mode if Inspector displayed a client with an Init section.
- Fixed issue where usage of [InitInEditMode] could result in a MissingReferenceException being thrown if rapidly loading and unloading scenes.
- Fixed obsolete warnings in Unity 6.4 and later.
- Support for dragging-and-dropping MonoScripts into Services components.
Version 1.5.5
- Added Mirror add-on package giving NetworkBehaviour the ability to receive sevices automatically during initialization.
- Added Photon Fusion add-on package giving NetworkBehaviour the ability to receive sevices automatically during initialization.
- Added support for generic global service initializers that implement a generic IServiceInitializer<T, Dependency1, ...> interfer and receive other global services in their InitTarget method.
- Cancellability improvements - added cancellation token support to IValueProviderAsync<T>, IValueByTypeProviderAsync and Any<T>.GetValueAsync and made initializers pass MonoBehaviour.destroyCancellationToken to them.
- Fixed reliability of async global service disposal in cases where user exits Play Mode while a service is in the process of being initialized.
- Fixed issue with AnyPropertyDrawer support of non-array collections like List<Any<T>>.
- MonoBehaviour<T...> no longer log TaskCanceledException to the Console if the MonoBehaviour is destroyed during asynchronous initialization.
- Fixed issue where dragging-and-dropping a component that implements IValueByTypeProvider to an Any<T> fields could result in an exception.
- Services component's defining type picker now groups value provider options under a group just like Service Tag for better consistency.
- Optimized defining type selection dropdowns so that they can better handle drawing a large number of options.
- Fixed issue where collapsing/uncollapsing a property drawer for an Any<T> array element could affect the height of property drawers for other elements of the same array.
- Fixed an issue where the initialization of a scene-based global service could fail if an Initializer was attached to it.
- Fixed issue with Init section clipping when Scale was set to more than 100% in Window settings.
Version 1.5.4
- Added an add-on for PurrNet with NetworkBehaviour<T...> base classes.
- Services component will now have a warning box if multiple services with the same defining type have been configured.
- Made IInitializable<T...> interfaces contravariant to make it more convenient to use things like Instantiate and AddComponent with arguments.
- Added Service.AddChangedListener(Action)/RemoveChangedListener(Action) which can be used to get notified whenever a global or local service or service provider changes.
- Fixed Obsolete member warnings in Unity 6.4.
- Fixed issue with Service Tag's Set Service Type menu not listing types of values provides by a component that implements IValueByTypeProviderAsync
- Fixed issue where 'Make Service Of Type...' menu item could be disabled for a component which had not been registered as a service yet, if another component of the same type was already registered as a service.
- Added new IValueByTypeProvider.IsSupportedType(Type) and IValueByTypeProvider.GetSupportedValueTypes() members that can optionally be implemented to customize which defining type options should be selectable in the Editor for a local service created from said value provider.
Version 1.5.3
- INullGuard.EvaluateNullGuard result can now include a text description about exactly what caused the validation to fail.
- A warning icon is now drawn in the Init section next to value providers whose null guard has failed. A tooltip describing why validation failed is shown if the icon is mouseovered.
- Made various built-in value providers provide descriptive warnings when their null guard fails.
- Fixed issue where Service Tag mouseover tooltip would only list the first defining type of the service instead of all of them.
- Service Debugger window improvements
- Extended context menu with new items: 'Ping Registerer', 'Ping Type With [Service] Attribute', 'Ping Script' and 'Find Clients In Scenes'.
- Services from inactive and disabled Services components and Service Tags are now listed reliably.
- Click to ping now also works with inactive services.
- Added GetComponentFromService base class. This can be extended to easily create a value providers that retrieves a component from a GameObject to which a service of a particular type is attached. E.g. could get the Collider from the Player service's GameObject.
- Help boxes drawn in the Inspector now have word wrapping support.
- The Services component's Editor now displays a warning box if a service is a value provider which can not provide a value matching the defining type assigned for the service.
- [Service(LoadScene = "SceneName")] can now load scenes in the Editor even if they are not included in Build Settings.
- Fixed errors when trying to unregister services from a Services component containing services with invalid defining types.
- Fixed obsolete warnings in Unity 6.3 and newer versions.
- LocalizedString now implements IValueProviderAsync<string> instead of IValueProvider<string>, because trying to resolve a localized string synchronously could result in deadlocking.
- Services and ServiceTag performance optimizations.
Version 1.5.2
- Prefab instance reference support - assigning a prefab asset into an Init argument field using the Inspector now results in a popup asking if you want to reference the prefab asset or an instance of it. This makes it very simple to reference prefab instances that are only instantiated at runtime without having to write any code.
- An error icon is now shown next to cross-scene and prefab instance references if the value is missing.
- A warning box is now shown in the Init section if any value provider is unsable to provide a value for some reason.
- Cross-scene references and prefab instance references now support providing their values asynchronously. If any client has pending value requests, the value will get provided the the moment that the scene in question is loaded or the prefab in question is instantiated into a scene.
- Cross-scene Ids are now visualized as "Id" instead of "Ref" in the Inspector.
- "Copy Id" was added to cross-scene reference context menu.
- "Generate New Id" was added to Id Tag context menu.
- Further improvements made to scene-based service handling.
- Added DontDestroyOnLoad option to [Service] attribute.
- Fixed wrong tooltip description in the service tag of local service with availability set to Scene.
- Service Debugger now also lists info about global services that failed to be initialized.
- Scenes targeted using [Service(LoadScene = "SceneName")] are now loaded in the Editor even if they are not included in build settings. In this case a warning about the scene being missing for the build profile is shown.
- Extended ability to ping local services in edit mode via the Init section.
- A warning box is now shown in the Services component if any service in it has an invalid defining type.