# Scene & Class Setup

To make use of the **Drag-and-Drop Inventory System**, some setup is required. Refer to the Party Based RPG demo game for reference.

## **Create a new layer**

The module uses a layer for displaying UI inventory. Create one called ***UIInventory***.

![](/files/-MZk2F21aNlaAp8XZHRS)

## Canvas

The prefab `Canvas 1920x1080` is a UI Canvas which you may find helpful to start with. This is the canvas used in the demo scene.&#x20;

The "Demo Objects" and "Player Portraits" (highlighted in red below) are likely able to be removed for your project. Be sure to use the demo scene first to better understand what these sections do, as you may be able to make use of them for your project.

![](/files/-MZk1AP0mpCreY1f8u8D)

{% hint style="info" %}
Check the "*Inventory Module*" object and it's children in the world scene of the Party Based RPG demo game to see these objects in context.
{% endhint %}

The objects turned off, *Inventory Panel*, *Box Inventory Panel*, and *Small Box Inventory Panel*, are useful if you'd like to create your own inventory panel prefabs using these as starting points. They are used in the demo scene, but can be utilized in your own projects, modified or unmodified. Be sure to create your own original prefabs from these objects.

## **Inventory Light**

This light is used to illuminate the UI inventory objects. While this is not required, we suggest you set up your inventory system before modifying the lighting.

{% hint style="info" %}
If it makes sense for your scene, try modifying this based on the lighting in the location where the player is, so that inventory is darker in darker locations, and bright during the daylight.
{% endhint %}

## **Held Item Parent**

This is the parent transform for the item being held by the `OnScreenItem` script. This is required, though you could technically replace it with another parent if you have a reason to.

## Required scripts prefab

Bring the prefab `Inventory Module Required Scripts` into your scene. Alternatively, you can add the scripts `OnScreenItem` and `PanelManager` into your scene. These scripts are required for the **Inventory** system to work.

[**OnScreenItem**](/magic-pig-games/game-modules-4/game-module-systems/inventory/scripts/onscreenitem.md)\
This script handles inventory objects when they are "held" by the player but not in a specific inventory. See the [section on this script](/magic-pig-games/game-modules-4/game-module-systems/inventory/scripts/onscreenitem.md) for more details.

Remember to populate the "Required" references in the inspector.

[**PanelManager**](/magic-pig-games/game-modules-4/game-module-systems/inventory/scripts/panelmanager.md)\
This script manages the various UI panels for visual inventories. Note that the `playerInventoryPanel` is meant to always be in the scene, while panels that populate `otherPanel` will be instantiated and destroyed at runtime -- these are panels which represent the inventories of other objects like treasure boxes, or enemies. See the section [on this script](/magic-pig-games/game-modules-4/game-module-systems/inventory/scripts/panelmanager.md) for more details.

Remember to populate the "Required" references in the inspector.

## `IHaveInventory`

Any class that has an inventory should implement `IHaveInventory`.

{% hint style="success" %}
If your custom `Actor` class inherits from `GameModulesInventoryActor`, then you already have most of what you need set up for your player inventory!
{% endhint %}

```csharp
// Required methods for IHaveInventory
public GameItemObjectList DisplayableInventory();
public Spots DisplayableSpots();
public void RegisterDisplayableInventoryWithRepository();

public bool TakeIntoInventoryGrid(GameItemObject gameItemObject);
public bool TakeIntoInventoryGrid(GameItemObject gameItemObject
    , int spotRow, int spotColumn);
```

{% hint style="info" %}
Anything can have an **Inventory**. Logically, things like enemies, NPCs, shops, treasure boxes, and of course players will have inventories. However, you can utilize the inventories on other objects as well, such as the surface of a bed or table, or a pedestal in a dungeon, where a user has to place a specific quest item to trigger some in game event.

Creative use of the **Inventory** module can expand the value of the module, and easily create game logic that you would have to otherwise code yourself.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://infinitypbr.gitbook.io/magic-pig-games/game-modules-4/game-module-systems/inventory/setup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
