How to reference a non-player, actor owner inside a component

I am trying to create a chest inventory system. Currently I am having trouble initializing chests with their own inventory.

The chests have item actor arrays which are instance editable. The chest on the left is supposed to have the LionAxe and the chest on the right is supposed to have nothing. When I start the game however, they seem to share the exact same inventory, the items even move the same on the grid.

I believe the problem is that I use the GetActorOfClass node in the inventory blueprint to get the inventory component when I am initializing the grid. I don’t think this gets the particular owner of that component, but instead gets all chests, therefore it treats all chest inventories the same. I think if I could get the actor owner reference for this instead, it would work. I can’t figure out a way to get that though; I get error messages with every other node I try. Does anyone have a method to do this.

Most of my roadblocks are reference releated.

Hey @LiquidGainz!

Yes, it’s definitely reference related. “Get Actor of class” is going to return the one closest to world 0 most of the time. You’re activating chest 2 but getting chest 1 inventory, most likely.

Instead of “On Initialize” doing everything, I’d suggest making a custom event on the widget blueprint you have there, and casting to that widget to activate the custom event from the chest object or player, after the widget has been created. That custom event should have an array input node, so you can pass the inventory array through from the chest to the widget.

You are right that you should create a new widget every time a chest is opened then remove it from parent when it’s closed.

I don’t know what your “Close chest” widget code looks like but you certainly need to use “Remove from parent”, so then when you initialize a new chest inventory widget you have less chance of using the old one by accident.

I really hope this helps you out, feel free to ask more questions! :slight_smile:

1 Like

You should create an interaction system that handles specific targeting of actors vs “Get all actors” variants.

Sorry, I am really ignorant when it comes to casting and references. What type of “Get” should I use here?

Yeah, you’re going to need a bit more understanding, my apologies. There’s a good lack of code here, I have no idea how you’re even accessing specific chests. As @Rev0verDrive said, you’re going to need to make an interact system first. There are a lot of tutorials for that, though!

Disclaimer: This link is not affiliated with Unreal Engine, Epic Games, or their partners.

Once you’ve done that, you’ll more than likely have a better understanding of what’s going on.

You shouldn’t set a reference like this on BeginPlay, because then each chest is using the same reference point. You need to set the chest reference for the Widget being created WHEN the player interacts with the chest, not when the game starts. :slight_smile: Also your cast won’t work because you don’t have an input object. Casting is not like “fishing line”, it’s like “remolding”. It’s not a “Go get this” it’s a “Reshape this”, so it needs something to reshape. :slight_smile:
Hope that makes sense! Go get that interact system! :smiley: You’ve got this!

Thanks man! I have an interaction system but wasn’t using it as an event on the blueprint, I now am. I also pulled everything off of initialize. I just don’t know what to plug into the cast here in order to get to the inventory widget. I create the chest inventory widget on the HUD. I have experimented trying to create the widget in the BP_Chest actor instead, but I still need to cast to the HUD in order to actually display it. What is the best way to get the widget reference here so I can feed this particular chest’s inventory.

Now, I may be in the very beginning of unreal engine 5, but my question would be, why create a widget? Shouldn’t he make a an interface, checking if the character is implementing it and then once near the chest, activate it with a button for example and add it to the inventory or a variable in that case?



I managed to get the reference to BP_Chest in the chest inventory widget but the problem of all chests sharing inventory persists.

Hey @LiquidGainz, looks like you’re doing a lot and learning but not quite getting there so let’s prune back a little bit. For instance: What does this do? Does this boolean get used anywhere else?

Could you show the rest of the “Show Chest” event? and the “Initialize” Event on “WB_Chest inventory Grid”?

Absolutely! My bad about that “inventory Created” variable check on the “Interact With” event, it is vestigial. I was trying to get the reference some other way then changed course, but I only deleted part of that experiment, so all that is deleted now and interact just runs the “Interact With Target” event.

This “Show Chest” function is on the HUD BP. It regulates whether the chest menu is visible or not, I figured it would be best to place all these HUD and menu events and functions on BP_HUD.

This is the “Initialize function.” I created the foundation for this whole grid inventory system by following “Reid’s Channel’s” guide on the subject. I’ve been trying to flesh it out and customize it from there.

Okay so looking over all of this I can say with certainty that you have no method of seeking out a specific chest. You need to find a way to determine I want this chest not that chest. Sphere trace, line trace, anything to return a specific item. Does that make sense?

Like in a first person game you have your reticle, you open the chest it’s pointed at. The reticle is a line trace and it returns the first object it sees when asked. If it is a chest, then run chest logic using THIS chest as input. Same with sphere but it’s more of an area. Does that make sense?

2 Likes

Got it, I will figure out something in the “interact” path.

The problem was that I needed to create the chest inventory each time a chest is opened, not just the first. So, every time a chest is opened the inventory has to be constructed since they all share a widget. So, after the widget is created, I added a “Create Chest Inventory” function to the upper path.