Spawn an itemObject in world

MagicTimm

Member
Hi, i think you made the ItemObjectSpawner.cs exact for this. But how can I get the item id and what must I add to make a ready for pick up item?
Maybe you could add a prefab to the demo scene for this case. It would be very handy.
 
Yes ItemObjectSpawner is used to spawn ItemObjects anywhere in the scene.

What do you meant by Item ID? You might be confusing the Item ID and the ItemObjectSpawner ID, they are two distinct things.

The ItemObjectSpawner has an ID such that you can find it anywhere in the code. All you need is to add an ItemObjectSpawner component somwhere in your scene (I would add it to your "Game" game object), make sure its ID is unique if you have multiple ones.

The you can get the ItemObjectSpawner with the id using the Get Global function, from there you can spawn an ItemObject:
Code:
var itemObjectSpawner = InventorySystemManager.GetGlobal<ItemObjectSpawner>(id);
itemObjectSpawner.Spawn(itemInfo, position);

I believe the Demo Scene has an ItemObjectSpawner on the "Game" gameobject so you can see how it's setup. The only requirement for the prefab is that it must have an ItemObject.
 
Yes ItemObjectSpawner is used to spawn ItemObjects anywhere in the scene.

What do you meant by Item ID? You might be confusing the Item ID and the ItemObjectSpawner ID, they are two distinct things.

The ItemObjectSpawner has an ID such that you can find it anywhere in the code. All you need is to add an ItemObjectSpawner component somwhere in your scene (I would add it to your "Game" game object), make sure its ID is unique if you have multiple ones.

The you can get the ItemObjectSpawner with the id using the Get Global function, from there you can spawn an ItemObject:
Code:
var itemObjectSpawner = InventorySystemManager.GetGlobal<ItemObjectSpawner>(id);
itemObjectSpawner.Spawn(itemInfo, position);

I believe the Demo Scene has an ItemObjectSpawner on the "Game" gameobject so you can see how it's setup. The only requirement for the prefab is that it must have an ItemObject.
Hi Sangemdoko,

I added ItemObjectSpawner on the "Game". My prefab also has an ItemObject. I also called GetGlobal function but encountered this error
1630003233172.png
Do you know what's going wrong? Also, can you provide an example of "itemInfo"? what should I put there? like ("weapon",1)?

Thanks!
 
Most likely you do no have access to our scripts because you haven't made an assembly definition that references ours for your own scripts.
There are a lot of tutorials on assembly definitions that you can find online. Here is the Unity documentation for it:

As for ItemInfo a simple example would be:

Code:
// Create an Item from the Inventory System Manager by name.
var potion = InventorySystemManager.CreateItem("Potion");

var itemInfo = new ItemInfo(potion, 1);

//Or you can even do
var itemInfo = new ItemInfo("Potion",1);

That's being said ItemInfo is much more than just an ItemAmount. It also has reference to an ItemStack and an ItemCollection. This way when you try to find an item in an Inventory, it won't just tell you the amount, but also where it is stored exactly. That is espcially useful when you organize your items in different ItemCollection or when you have multiple stacks of the same item.

I hope that makes sense. you can learn more about the definitions of ItemAmount, ItemInfo, etc... here: https://opsive.com/support/documentation/ultimate-inventory-system/getting-started/terminology/
 
Top