playMaker

Author Topic: Inventory with Scriptable Objects  (Read 1136 times)

EpicMcDude

  • Playmaker Newbie
  • *
  • Posts: 45
Inventory with Scriptable Objects
« on: October 09, 2021, 02:27:37 PM »
Hi,

I have 2 custom actions to Get and Set my Scriptable Objects (SO) information onto my FSMs, as well as a variable type definition of my SO.

I'm trying to do an Inventory where when I pick up an item in the world that has the SO variable I set it at, it sends an event preceded by Set Event Data Info with the object type of what my SO it is. (image 1)

But I'm having trouble finding a workflow between SO and hashtables/array list for the Inventory UI.
Each SO has a prefab slot for UI and then that UI prefab has an FSM with the SO variable and is instantiated, so that I can get the stats for each object. (image 2)

But I'm very confused with the SO workflow, the button on image 3 only works for the first item that I click on, when I click on other items the "Set Info" event doesn't fire.

I'm not sure what the proper way to add UI elements based on item pickup is?
Also not sure how to display Scriptable Object info from a list or hashtable.


djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Inventory with Scriptable Objects
« Reply #1 on: October 09, 2021, 11:08:37 PM »
Hi.
Maybe this tutorial can help :


it uses id number for items.
you can make a main SO with a List<YourScriptable> (your Orange and other items)
and a List<int> (the id number)

then you need to make a action (SO_GetItem) and find the index on the id list
and you can get the correct scriptable with that index

EpicMcDude

  • Playmaker Newbie
  • *
  • Posts: 45
Re: Inventory with Scriptable Objects
« Reply #2 on: October 10, 2021, 08:15:52 PM »
Hi.
Maybe this tutorial can help :


it uses id number for items.
you can make a main SO with a List<YourScriptable> (your Orange and other items)
and a List<int> (the id number)

then you need to make a action (SO_GetItem) and find the index on the id list
and you can get the correct scriptable with that index

Hi Djaydino,

Awesome help, that video was quite helpful! Having you go through states literally frame by frame helped me understand this a bit more.

I'm a bit confused with a couple of things since my inventory system is different than yours.

I don't have slots, each item is created at runtime in the inventory as a UI button prefab clone, so I don't know how to get the index of the item the player clicked on?
I also added a new field for my SOs which is the ItemID since you said in the video it's great to use that to communicate with other lists/FSMs. But I don't quite know how to use this ItemID to identify the item I've clicked on either?

Right now my inventory manager is just adding items to the UI inventory and my inventory, like in the image.
Every time I grab an item I send the event AddItem to the inventory manager and also add to the inventory UI object.


Each UI button prefab holds a variable with the SO associated with them, and since they are buttons, I just click on them and send the event UpdateInventoryUI and set the text.
But is possible to do this by getting the index and then the information of the object within that index?

Thanks!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Inventory with Scriptable Objects
« Reply #3 on: October 12, 2021, 07:11:38 AM »
Hi.
maybe have a fsm on the prefab and use on click there.

When you spawn a new object,
store the object in a variable.
Then use Set Fsm Gameobject to set a variable with the gameobject to the ui display on your spawned button.

Instead of Create/destroy object you should look into pooling this.