How to cast to an actor with no parent/inheritance?

Hello all,

I’m trying to cast to an Actor blueprint I’ve created, from the regular event graph from my player character actor. I found a workaround to casting to this blank-slate class online, but I always get this yellow warning every time I compile, which is worrying. I’ve attached an image of how I cast to this blueprint.

My question: how does one properly cast to an actor of this variety? I simply cannot find an answer to this online, even in Epic’s blueprint casting examples. Of course, maybe I haven’t looked hard enough, but I need some help here now. I’m not sure if this casting works 100%, but it might? I just want to get rid of the warning and be sure things are working correctly whenever I go to debug/troubleshoot things I’ve made.

Thanks for any help in advance!

The warning in your screenshot is telling you that it is pointless to cast the object from Game Manager to Game Manager as this won’t do anything. The whole point of using a cast is to cast an object as a different type in the inheritance chain. Is it possible this is a typo and you really meant to cast Game Manager to a more specific type that you inherited from Game Manager. To answer your question in the title, you cannot cast an object to a type that is not related by inheritance.

I’m confused on what I need to get then. For instance, if you’re casting to a character class, you use the “get player character” node, and that makes sense. But if an actor doesn’t inherit from something like that, how do you cast to it? If you don’t put anything or a wrong node in the “object” pin, the class will either not compile or the cast will fail.

Surely there is a way to cast to something like this… if there really isn’t, what are my alternatives??

The important thing to remember about casting is that it actually doesn’t do anything. You aren’t actually casting your object to another type you are just acknowledging that it was already that type. So if I have an Apple I cannot cast it to an Orange. The cast will fail because an Apple is not an Orange. But if I have a Fruit that is an Apple I can cast it to an Apple or if I have a fruit that is an Orange I can cast it to an Orange. Casting didn’t make the Apple an Apple, it already was. That is all casting does.

In UE4 you are always inheriting from something. All actors inherit from AActor. So if you create an Actor blueprint called MyActor you just created a new object that inherited from AActor. Now if you somehow get a reference to that AActor the reference might say it is an Actor, but we both know it is actually a MyActor so we can cast it to MyActor. That doesn’t change the object, it just lets the reference pointer know that it is really a more specific type which is something we already knew.

What is likely happening in your case is that the object you need to plug in to an input pin is completely unrelated from the one you have. In which case there is nothing you can do except find the right object. Casting isn’t going to help.

If you have a specific pin you are trying to get the right value for, let me know and then we can see how to get it. A large part of learning blueprints in UE4 is figuring out all of the object types and how they are related.

That is some great information to have, thank you for that explanation.

I went searching from the top of the node list in blueprints for something I could plug in, and I found it.

Here is my setup now, error-free. Thank you so much, Dartanlla.