I am having some trouble understanding how to go about creating actors with separate inventories. I’m using drag/drop and have a functioning though basic inventory system for my character and another actor (a fireplace). I worked out how to get drag/drop between the two widgets (character and fireplace) but after having some of the AI NPC build another fireplace I noticed they both share inventory or register the same. I think I know why but I’m not sure how to get past it.
This is my suspect. My first thought was perhaps I just need a way to re-initialize the “fireventory” but seems like it needs a way to create a new array if a new fireplace is built.
The inventory for the fireplace is initialized via a HUD widget graph while inventory addition, subtraction, stacking and DataTable information is handled from the fireplace’s actor BP graph. It’s essentially pulling the same info that is built after I’ve added some things to the fireplace whenever a new one is constructed. If I were to initialize the inventory again I assume it would wipe what is in the inventory since it is all linked back to one array for fireplace inventory items. I was looking at “Make Array” or something along the lines. Any advice?
You need to look where you store data and what UI reads, if somethings shares same inventory that means you somewhere look on same array for some reason.
You using actor component for inventory. right? inventory array should be part of this component so each individual component in actor have sperate data.
HUD also should not initiate inventory as this is something that component should do at it’s creation, HUD should be just a editor of inventory data at pointed component. So make UI widget that accepts inventory component reference as it’s parameter and make UI operate inventory only at that pointed component, nothing else, so you are 100% sure what UI is currently operating. Such widget would be highly reusable anywhere and could be used on any thing that has inventory component.
In web design concept that also fits to any software that operates on data set (like inventory data) that oyu might be interested in, it called “Model-view-controller” pattern
In your case:
-Model = Inventory array in component and item objects containing them
-Controller = Inventory component itself
-Viewer = UI widget
If you follow this pattern you should be able to avoid problems you having. Viewer should be like a device that you plug to controller and tell controller to get and edit data, and at any moment oyu can unplug this device from one controller and plug it to controller. Controller should be device with stores the inventory and has commands to edit it which plugged viewer would send and edit the model which is inventory array it self and items contain it.
The image shown is an inventory component and to correct myself the widgets don’t call the shown initialize function. Theirs is to construct and create the slots setting them into specific rows for the widget. They call respective custom Get_Inventory functions in inventory component. You can see in the image that function is run on begin play for the inventory component. It is also run directly under the player characters inventory initialization.
Do I need to separate this and make it into a function I can call whenever a new fireplace is constructed? This would still only be one though I’m wondering how to create a new one each time in inventory component. From what I’m gathering I need to have the array inside the fireplace actor BP? Bare with me if this is not exactly correct.
Thank you for your help so far, I’m trying to actually understand this. I feel like its setup like you are saying and of course it will always pull the same data from the one array. For the player character, this is fine but not for object inventories.
The fireplace BP does not have inventory component added through upper right box but I am still calling the inventory component which has functions to add and subtract from inventory. In this area mainly am checking the inventory component and slots to see if they are of a certain type.
Thank you for the guidance and I tried responding some days ago but I have not seen approval of the comment.
The system setup here is very similar to what you describe. I have an Inventory component that handles functions to get inventory, check to see if its stack-able or to get the inventory array. It is an array of inventory item blueprints.
I’m not sure if I’m understanding you correctly but I added my inventory component to my actor blueprint. Made an array in the graph for the actor and initialized/built it in construction script. To test I tried to get the array reference from inventory component then set it to the array made in the actor’s BP. I can see it is generating the array and also setting it but when I open the HUD I get no population of slots. It doesn’t appear to actually set it. When I try to look at debug for inventory component I can’t get it to show information on the array. If I check the actor (other blueprint) you can set debug and see the list of inventory item references. Both get and set show population of the array in actors blueprint.
Here is an image to show what I mean. This is for the actor (world object with inventory). I’ve added the inventory component here so I can reference it directly. From what I can gather you want to have two arrays for this. One in inventory component and one in world actor. To always set the array for inventory component with whatever you are accessing, before opening the HUD. I assume you perhaps cannot simply set an array like this though I am not sure probably need some more pointers if this is the case.
The double image appearance is just to show both arrays display as populated with references.
The bottom array is referenced from the Inventory_BP component I recently added.
Still not sure why the array is not being set. From what I’ve looked into with I cannot find or do not know the right wording to set an array in a component from another blueprint. Seems this should work but it does not so I must be doing something wrong. I don’t know what that might be.
Ok I managed to get it to work partially but it is still sharing the inventory of the first one. It is looking to a specific array each time (it always looks at the same place). I am wondering how I would go about making a new array when a new actor is placed. Do I need to have a set number of arrays? Can I set this up to make a fresh array each time? This is sort of the root of my question.