Problem with casting to a blueprint

Hello,

So I’m trying to cast to a blueprint called myCharacter. Within that blueprint, I have a variable called marker1Exists.

I’m trying to write the number ‘1’ with my HUD, if marker1exists.

However, the moment I test this and hit the play button, I get ‘Cast Failed’ continuously appear.
Am I doing something wrong?

Maybe i don’t understand from which variable you want to cast to MyCharacter, but try:
Right click → Get Player Character >>> Cast to MyCharacter (so instead of “Casted My Character” node you’ll have “Get Player Character”)
Sorry if i’m unclear, it’s late here :slight_smile: Good night.

As the previous poster said, you must make sure that ‘Casted Character’ references a valid Character. It should point to an instance of MyCharcter or one of its sub-classes. If your aim to to get a reference to your-own player, then use GetPlayerCharacter node as @Slavq sugested.

Thank you! This works. Do you think instead of using ‘get player character’, ‘get player controller’ would be a better idea?

It depends where you have this “Marker1Exists” variable. If it’s in your player class, then use Get Player Character, because from there you can cast it to… Your player class (which is of “Character” type)

So if this variable would be (for example) in your player controller class, then Get Player Controller → Cast to “YourPlayerControllerClass” - because you need to access an object of this class. To undestrand it better, i recommend to read a little about some object-oriented programming things, like classes, interfaces, etc. Example: Buckys C++ Programming Tutorials - 12 - Introduction to Classes and Objects - YouTube
Blueprints are classes - and they work practically in the same way. (because it’s like a regular programming, just using nodes instead of lines of code :slight_smile: )