New at coding, need help understanding and cleaning up code.

Been stuck on this problem for a few days and I feel like it’s simple but I’m not competent in code to figure it out. I’m trying to add an inventory functionality but I’ve followed a few tutorials and some use BP and some use C++ so in the learning process I’ve confused myself into another hole when I was trying to merge the two. The C++ code is a onused function which interacts with any usableactor that I have raytraced to and picking it up can be put into an array of inventory but that’s someone else’s code so I tried to follow someone else’s mixture of c++ and BP with “interacting” (basically onused but different wording) in hope’s of understanding it so I can put it together. With this second code I’m able to ray trace and add it into another list of inventory array and am able to display it visually through the hud “inventory” but I don’t understand why the first code isn’t able to be picked up on the second code’s array and vice-versa when they are basically the same-ish. The thing that’s making me confused is that the first one is in the character while the second one is in the controller so I’m inexperienced in trying to “talk” to each other when trying to grab functions from each other.

I’m stuck at the part where i’m trying to add the picked up actor to my list of inventory array, I’ve tried to add the functionality of the second tutorial and embed it into the first onused function but it makes my game teleport to the default map and then when I try to use it again on the usableactor it deletes my controller but the game keeps going? I’ve never seen this happen

I’ve tried to add a function that happens in the controller through casting it to character and playercontroller which I feel like is nooby and probably wrong, this is definitely where the code is making me teleport to the default map then deleting the cnotroller. The additemtoinventory function happens in the next code snippet which is in the controller and it works when I use the second input code I followed but not with the input of the first code which I want to merge it with so I know this function is working

If someone would like to explain how to do this it would be great! If you would like more code to see let me know what you need to see. It has to be with the way I wrote that last code in the first snippet but because i’m very new and inexperienced a lot of his code is being checked and I don’t think I’m understanding what’s being checked or not so it’s possibly not being passed because of my part of the code being the error.