Redirect to the Docs main page.Docs

Items Options

Creating an Item Option SO

Learn how to create and configure options using Scriptable Objects (SO) in the Ultimate Grid Inventory system.

Learning How to Create Options with Scriptable Objects

Options in the Ultimate Grid Inventory system are managed through Scriptable Objects (SO). This system relies on event triggers to execute actions. By creating an event associated with an option and then writing a script to handle that event, you can customize the behavior of your inventory options.

In this documentation page, we'll walk through setting up a Discard Option as an example.

Creating the Option SO

To start, create a new Option SO using the Unity creation file system.

Creating Discard Option SOLoading image

After creating the Option SO, fill in the necessary fields:

Filling the fields for Discard Option SOLoading image

Understanding the Properties

Option Event

  • On Inventory Item Execute Option Event Channel So: This event is what the script will listen to and perform the action when triggered.

Option Metadata

  • Display Name: The name that will be shown in the game for this option.

Option Settings

  • OptionsType: Defines the type of the option for adding or removing from the InventoryMetadata class.
  • Order: Determines the position of the option in the list. A higher number will appear lower in the sequence of options.

In the OptionsType file, you can add new types for your options:

public enum OptionsType
{
   INSPECT,
   EQUIP,
   UNEQUIP,
   OPEN,
   DISCARD,
   // Add your new OptionType here...
}

Creating the Event Channel for Option SO

Creating an event channel for your new Option SO is straightforward. Follow these steps:

Creating the Option Event Channel SoLoading image

After creating the event channel, attach it to the option you created earlier. Your option configuration will look something like this:

Finishing the Option SOLoading image

Creating the Option Listener

To add functionality to your option, you need to create a MonoBehavior script that listens to the event. Attach this script to a GameObject in your Scene. Here’s an example MonoBehavior:

using Inventory.Scripts.Inventory;
using Inventory.Scripts.ScriptableObjects.Events;
using UnityEngine;
 
public class DiscardOptionExample : MonoBehaviour
{
    [SerializeField] private OnInventoryItemExecuteOptionEventChannelSo onInventoryItemExecuteOptionEventChannelSo;
 
    private void OnEnable()
    {
        onInventoryItemExecuteOptionEventChannelSo.OnEventRaised += HandleDiscardOption;
    }
 
    private void OnDisable()
    {
        onInventoryItemExecuteOptionEventChannelSo.OnEventRaised -= HandleDiscardOption;
    }
 
    private void HandleDiscardOption(InventoryItem inventoryItem)
    {
        // Add your action here...
        Debug.Log("Executing option...");
    }
}

Adding Option to an Item

Finally, add the option to the desired item. In the Group Options Settings field of the Item, add your newly created option to the list:

Option added to an ItemLoading image

Hit play, open the Options Menu, and click on your option to see the action logged from your script:

Logging the Option ActionLoading image


With these steps, you’ve successfully created and configured an option for your inventory system. Continue to explore other features and customization options to enhance your grid inventory!

On this page