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

**URL:** <https://forums.unrealengine.com/t/casting-successful-but-error-shows-when-using-the-as-pin/2152036>\
**Category:** Blueprint\
**Tags:** error, actor, casting, inventory, event-graph, actor-blueprint, inventory-system, unreal-engine, cast, Components, Blueprint, question\
**Created:** [November 26, 2024, 2:02pm UTC](https://forums.unrealengine.com/t/casting-successful-but-error-shows-when-using-the-as-pin/2152036 "2024-11-26T14:02:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maximum.Dino](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Maximum.Dino](https://forums.unrealengine.com/u/Maximum.Dino)\
**Post date:** [November 26, 2024, 2:02pm UTC](https://forums.unrealengine.com/t/casting-successful-but-error-shows-when-using-the-as-pin/2152036/1 "2024-11-26T14:02:33Z")

</div>

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](https://youtu.be/b2atcZWYi3E?feature=shared) 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](https://drive.google.com/drive/folders/1ZS4a-98_dVbgyR3wa22hOwLHicfqIonS?usp=drive_link)

---

<div class="post-metadata">

**Author:** ![Auran131](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Auran131](https://forums.unrealengine.com/u/Auran131)\
**Post date:** [November 26, 2024, 2:37pm UTC](https://forums.unrealengine.com/t/casting-successful-but-error-shows-when-using-the-as-pin/2152036/2 "2024-11-26T14:37:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Maximum.Dino](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Maximum.Dino](https://forums.unrealengine.com/u/Maximum.Dino)\
**Post date:** [November 26, 2024, 9:17pm UTC](https://forums.unrealengine.com/t/casting-successful-but-error-shows-when-using-the-as-pin/2152036/3 "2024-11-26T21:17:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Auran131](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Auran131](https://forums.unrealengine.com/u/Auran131)\
**Post date:** [November 27, 2024, 1:42am UTC](https://forums.unrealengine.com/t/casting-successful-but-error-shows-when-using-the-as-pin/2152036/4 "2024-11-27T01:42:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Maximum.Dino](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Maximum.Dino](https://forums.unrealengine.com/u/Maximum.Dino)\
**Post date:** [November 27, 2024, 3:33pm UTC](https://forums.unrealengine.com/t/casting-successful-but-error-shows-when-using-the-as-pin/2152036/5 "2024-11-27T15:33:09Z")

</div>

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.  
https://www.loom.com/embed/ea69f5f6c2d2420b8d1f30470a7bbe54?sid=f0a1ac00-046e-43f1-b483-a9b732ecb7ab

---

<div class="post-metadata">

**Author:** ![Nightwolf](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nightwolf/32/917179_2.png) [@Nightwolf](https://forums.unrealengine.com/u/Nightwolf)\
**Post date:** [November 27, 2024, 4:11pm UTC](https://forums.unrealengine.com/t/casting-successful-but-error-shows-when-using-the-as-pin/2152036/6 "2024-11-27T16:11:35Z")

</div>

OPs pictures

 ![Screenshot 1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/6/3/163452f2789cb888a8e351cabf8e08745e1e2b14.png)  
 ![Screenshot 2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/4/1/e413a2f1402d54c0d7126f29c9acef986ae04cc7.png)  
 ![Screenshot 3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/5/2/b52a316f65e5cd1399dc79ff3c819a377d74a2fa.png)  
 ![Screenshot 4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/f/c/ffc698a680dfda667b79adc24198c94b0814515a.png)

And [here](https://blueprintue.com/)’s a way to upload it better when it get’s complicated

---

<div class="post-metadata">

**Author:** ![Nightwolf](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nightwolf/32/917179_2.png) [@Nightwolf](https://forums.unrealengine.com/u/Nightwolf)\
**Post date:** [November 27, 2024, 4:37pm UTC](https://forums.unrealengine.com/t/casting-successful-but-error-shows-when-using-the-as-pin/2152036/7 "2024-11-27T16:37:59Z")

</div>

“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

> [@Nightwolf](#):
>
> ![Screenshot 2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/4/1/e413a2f1402d54c0d7126f29c9acef986ae04cc7.png)

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](https://www.youtube.com/watch?v=EUTfNNVLpGc&ab_channel=MattAspland)” to retrieve the information within

To be honest, what i’d do is watch a somewhat better [tutorial](https://www.youtube.com/watch?v=vHT4MhmwacE&ab_channel=RyanLaley), 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](https://blueprintue.com/) and send us the link

---

<div class="post-metadata">

**Author:** ![Auran131](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Auran131](https://forums.unrealengine.com/u/Auran131)\
**Post date:** [November 28, 2024, 2:11am UTC](https://forums.unrealengine.com/t/casting-successful-but-error-shows-when-using-the-as-pin/2152036/8 "2024-11-28T02:11:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Maximum.Dino](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Maximum.Dino](https://forums.unrealengine.com/u/Maximum.Dino)\
**Post date:** [November 28, 2024, 4:06pm UTC](https://forums.unrealengine.com/t/casting-successful-but-error-shows-when-using-the-as-pin/2152036/9 "2024-11-28T16:06:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Maximum.Dino](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Maximum.Dino](https://forums.unrealengine.com/u/Maximum.Dino)\
**Post date:** [November 28, 2024, 4:07pm UTC](https://forums.unrealengine.com/t/casting-successful-but-error-shows-when-using-the-as-pin/2152036/10 "2024-11-28T16:07:46Z")

</div>

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