Casting Successful, But Error Shows When Using the "As" Pin

I’m working on an inventory system and all has been going well, I’m following a tutorial basically to a tee, but I’m getting an error that seems to be saying that it can’t the ‘As BP_Item’ is inaccessible, ‘pending kill or garbage.’ I’ve made sure that the casting is successful, and the game completely works as I need it to, the error is the problem. I don’t know why it cannot access the item when it’s a successful casting. I’ll admit that casting is my weakness in this program, it’s something I have a hard time understanding, so maybe I’m getting it wrong.

I’ve also followed this tutorial step by step and maybe I’m missing something, but they’re not getting the error.
The final “destroy actor” node, if removed, the error does not happen. However I need that node and am not sure what the issue with it is.

Here’s a google drive folder of the error message, code and gameplay. Thank you!
https://drive.google.com/drive/folders/1ZS4a-98_dVbgyR3wa22hOwLHicfqIonS?usp=drive_link

this isnt a cast problem,
pending kill likely means you’re trying to access the Actor after you’ve destroyed it.

one place to start is to make sure you validate all your Get nodes, you can right click on them and ConvertToValidatedGetNode,

just make sure you handle the Invalid path if its not expected

3 Likes

Okay, so I checked what variables are valid and the BP Item reference that came from the cast is invalid. I don’t really know how to fix that? do you have any idea why it would be invalid? Also, I don’t understand why it thinks I’ve destroyed the actor already when there were no actors destroyed until the destroy actor node, which is the thing that specifically causes the error. the BPItem reference does work connected to some of the other nodes, though

i just looked at your code, the problem is you’re Destroying the actor in a loop so its trying to repeated Access/Destroy the actor.

you could use a ForLoopWithBreak but i prefer to encapsulate it in a function and Return out when you’re done.

2 Likes

I’ve tried using a function but I’m not sure where I’d start the function and what parts to keep. When I use the function, the error goes away, but only one item will show up in the inventory.

OPs pictures




And here’s a way to upload it better when it get’s complicated

1 Like

“Cast To” takes in a type of object, it’s easiest to think about this in the character pov
you have “get player character” which tells the cast to node hey he’s using “BP_ThirdPersonCharacter” and which one… so say there were multiple players all using ThirdPersonCharacter it tells it exactly which instance of the
object and then that allows you to access the information within that specific instance

so in your situation above, your using it correctly, you’ve hit an instance of item with your line trace and then are using the “cast to” to retrieve the information within

To be honest, what i’d do is watch a somewhat better tutorial, the one you sent over seems a touch hard to follow it’s possible you missed some small detail that makes it all work, that’s not obvious from the pictures/video available to us would be happy to look deeper into it if you don’t wish to restart just paste the bp here and send us the link

1 Like

in that case just move the DestroyActor/Return node to the ForLoop CompletedNode

this may be true for your LoadInventory too,

just ask yourself, what needs to be in the loop, obviously you dont need to destroy the actor repeatedly.

1 Like

thank you! Sorry about it being a bit messy, I’ll make sure to make it easier to access in the future.

Alright, I might try that tutorial series you’ve recommended. I appreciate it, hopefully I’ll have more success with that.

1 Like