How do I cast to a specific blueprint?

You are supposed to plug in an instance of your inventory manager there. If you dont have any, you should create a variable for it or do something like “Get Actor by Class” or similar.

Please consider reading some general programming documentation on what “Cast” actually is. Its just converting a type to a supertype (or vice versa) for an EXISTING objects.

1 Like

I have an inventory manager BP and an item BP. I want to cast from the item to my manager but everything I’ve tried plugging everything into the object input but nothing works.

I’ve tried getting a reference to self, a reference variable of the same type of BP, an actor reference and even an object reference but it either gives me an error or fails anyway.

What am I supposed to connect to this input?

Am I simply using casting the wrong way? I made a variable that references a inventory manager but I get the error in the following screenshot.

There’s “Get all actors of class” but all that does is return an array with nothing in it.

Yeah, you made that variable, but you are never filling it with anything. Think about it this way: how should the engine know, which inventory manager it should give you? maybe you got a few of them in your game?

Watch this one, maybe it helps you to understand what you need to do here:
https://www.youtube.com/watch?v=7wPhrve_vTA

Hey, looks like you’re unsure about what casting is, and what it’s used for.

When I first learned about blueprints and casting, the easiest way for me to understand how it worked was like this:

For example, you have a TriggerBox with an event ‘OnActorBeginOverlap’. When you overlap this box, the box doesn’t know what you are, except that you’re an actor. But you know that the only actor that will cross this box is you, a first person character. So, you can create a ‘Cast to First Person Character’ using the ‘Other Actor’ from the ‘OnActorBeginOverlap’ event.

After casting, you’re able to communicate with your first person character blueprint from the triggerbox blueprint now that you have a reference to the instance of yourself.

For your situation, using Inventory Manager and Item BP’s, you would typically have a situation like this. You have an object in front of you, and you want to know if its an item that you can pick up. So lets say you’re walking along, and you step on this unknown object. At first, your character won’t know what it is, so you need to make a test to see if it’s something you know, like a BP_Item. This is where casting comes in.

On the event that you walk onto this item, you cast that item to a BP_Item. If it succeeds, great, you now know that its a BP_Item and you have a reference to it, so you can interact with it how you want.

However, if the cast fails, that means the item is NOT a BP_Item, and you will not have a reference to it.

1 Like

Yeah most of the tutorials I could find showed how to cast to player character/controller/gamemode/etc. which is no help at all considering those things have built in get functions that point exactly to the blueprint you want. Trying to do that without any get functions gave me a headache. I didn’t realize how much I didn’t know about casting.

Thanks.

Thanks! That video helped.