Skip to content

Examples

The Addressables integration kit comes with an example scene that shows how to instantiate a game object from an addressable asset, as well as another one that pre-loads it in the background.

Example Setup

Due to how Unity Addressables is coded, it is not possible to share addressable groups, and thus the example scenes require some minor setup. This page explains the steps to do so.

Setup

After installing the Addressables package as well as the Addressables Integration kit from the Downloads page, open the Install window and proceed with the installation of the Addressables Example.

Addressables Install Examples

Once installed, click on the Select button or navigate to Assets/Plugins/GameCreator/Installs/Addressables.Examples/, where there are three items:

  • The scene 1_Instantiate_GameObject, which shows how to easily instantiate a game object using an addressable.
  • The scene 2_Load_And_Instantiate, which shows also how to instantiate a game object, but preloading it beforehand.
  • The prefab Cube_Prefab that is used as an example object to be used in both examples.

Before opening any scene, the Addressables settings must be configured. To do so, open the Addressables Group window by selecting from the top toolbar WindowAsset ManagementAddressablesGroups.

If you don't have any Addressables settings configured, the window will prompt you to create them. Click on the Create Addressable Settings and wait until it completes.

Addressables Setup Window

Now that the settings are complete, we can proceed to configure the examples.

Examples

Open the first example scene 1_Instantiate_GameObject. This scene has a UI that allows to instantiate a game object by clicking a button.

Select the Actions object at the bottom, which is responsible for instantiating the Cube_Prefab object. Before doing so, we need to register this asset as an Addressable Asset.

To do so, it's very easy. Simply open the Addressables Group window just like we did in the previous section, and drag and drop the Cube_Prefab prefab onto the window.

Addressables Addressables Groups

Now that the Cube_Prefab is marked as an addressable, head to the Actions object and click on the right-most object picker from the Addressable Reference field and choose the prefab we just set up.

Addressables Instantiate Addressable Game Object

That's it! Entering play-mode will allow to click onto the Instantiate button, which loads and instantiates the game object at the center of the screen.

The second example's configuration is pretty much the same, except there's another Actions component called Actions_Load, which preloads the prefab before instantiating it. All that requires is to choose the Cube_Prefab addressable reference from the object picker, just like in the previous example.

Addressables Instantiate Addressable Game Object

Entering play-mode will not allow to instantiate the object directly. Instead, the object must be loaded before hand. Once it's finished, the Instantiate button will become enabled and ready to be used.