[Making sure I have this right] Casting Between Blueprints.

Before I begin, I apologize for being so dense, I just want to make sure I’m processing this information correctly before I move on. (The Graphs will be at the bottom of this post.)

I’m currently following the Blueprint Communication Project in the UE Documentation and I’m on step 4.

I’m not entirely sure what “Cast To FirstPersonCharacter” is doing there, but I’m going to try to explain it in my own words and see if someone can’t help me or nudge me in the right direction.

Ok, so the way I see it, is that the “Cast To FirstPersonCharacter” blueprint in the level editor is firing off from the “BeginPlay” Node and sending everything after it, to the FirstPerson Character. Which means the event “GetSpawnLocation” and all other variables connected after the cast can now be seen and interacted with inside the first person character.

Even as I type it, it doesn’t sound right. I hope somebody can help.

's the graphs:

**Level Blueprint: **


FirstPersonCharacter Blueprint:

So imagine you’re going to a store for a friend, but you’ve never been to it before. You only know the street address. You have a list, but it’s not written in English. When you get to the store, you don’t know what to make of it.

Thinking about the most likely store you’d be sent to with a list, you “Cast” the store to a ‘grocery store’.

IF the store is a grocery store

**If not
**

Either way- casting didn’t change the type of store it was, however, you were able to interact with the store in a way that made sense for what kind of store it was. Imagine going to a gas station for bacon. The store didn’t represent ALL grocery stores or convenience stores, did it? Of course not. It was only one instance of the store type it was. All grocery stores have eggs, but they’ll be in different places and the store will have a different amount. All stores have an inventory, though.

In a similar way, the object reference that you cast is always the same class- just an instance of that class. Casting doesn’t change the type the object is, however, it does let you treat the object as the casted type.

“sending everything after it” aren’t the best word in this case but beside that this sounds correct. The point is that GetPlayerCharacter returns a reference to any character. At that point it isn’t known if this character is a FirstPersonCharacter or not and therefore you don’t have access to any variable, function or event that additionally exists in your FirstPersonCharacter. Each FirstPersonCharacter is a Character but not each Character is a FirstPersonCharacter. So you’re casting the character to FirstPersonCharacter. If the character is a FirstPersonCharacter it has success and you get access to all variables, functions and events within your FirstPersonCharacter. If it fails you know that the character isn’t a FirstPersonCharacter.

Hey, so I’m also having a problem with casting, and this analogy you linked makes a lot of sense to me.

The only part, I guess the mental road block, is this section: “What you need to do is to cast each element of the array to the class ‘Woman’”

I get what the cast node does, I guess I just always have a hard time figuring out “where” to put the cast node in. Thanks for the link.