Create a generic cast with node blueprint

Hi. I have two blueprint actor created from static mesh (a cube and a cylinder).
It’s possible to create a one generic cast in blueprint that select which static mesh PG hit at runtime, instead of two separate cast (example cast to cylinder and cast to cube)?

Yes, You create a Parent Class (e.g. BP_Primitive). Add everything you need to the parent class. Then create a child class… BP_Cube, BP_Cylinder and simply change the mesh.

Casting should now simply cast to BP_Primitive.

You can also add variables to the Parent class. Configure them in the child … fully accessible through the same simple parent class cast.

Thx for answer but it doesn’t work at all for me. I need to access to a custom event inside bp cube and bp cylinder (both with same name). If i cast to a parent in blueprint editor, i can’t see custom event inside child, i need to cast to a cube(child) to see custom event.

I try to explain what i need: my goal is to create a blueprint graph like “cast to xxx → execute custom_event”, where xxx is a name of a blueprint actor whit PG interact at a runtime and determined at runtime. A solution for that could be a cast with 3 input (1 exec, 1 object and 1 “name”, where name are the name of a blueprintactor). It’s possible to create that?

If you’re working with unrelated classes, use an Interface. You don’t even need to cast. You send a message to an actor, it’s then up to that actor to do something about it. Each actor can implement the same function (or event if we’re not returning data) in a different way, or not at all.


If i cast to a parent in blueprint editor, i can’t see custom event inside child, i need to cast to a cube(child) to see custom event.

If you’re working with Inheritance, have the pertinent event in the Parent. Children can override it. Call the event for the Parent class and each Child will interpret it differently.

As in:

  • parent + two children

image

  • in the parent:

image

  • in the child:

You can now call the parent class’ event for the child and the child will fire its own instance of that event.


And you can actually do both as well:

image

Now the child will first execute the parent’s event, and then add its own stuff.

THX!!! It Work Perfectly!!!