Sharing blueprint function between actor/Pawn/Character classes

How would you add same function to all of your actors/pawns/characters without reimplementing them on all of them from scratch ?

Is there any blueprint friendly way to do this ?

how about a function library. pretty sure that would allow you to create a function usable by any class though it does have its own restrictions.

well, I need to use the character class and at the same time actor class for simpler actors and at the same time I have a lot of similar functionalities that needs to be implemented on a higher level affecting both.

Here is an simplified version of the class hierarchy.

Lets take into account a simple function like rising alarm when seeing the main pawn. Both definition and implementation of this function would be the same for all the classes inherited from “MyMasterActor” and all the classes inherited from “MyMasterCharacter”. Technically both are branches from the “Acror” class. and I seems like I would need to modify the actor class itself to be able to have functionality shared between them? Am I missing something here ?!

267409-classes.png

Yea make a blueprint function and choose actor to be the parent class.

so whats the issue? if you make the parent class actor then it can be implemented in any class which inherits from actor, this includes pawns and characters. think of it like this your creating a function that can be used in any class. it like the apply damage node for example all this node does is run a chunk of code and can be called in any actor to do the same thing, in your case the only difference is that your writing the code in bp instead of c++, the functionality is the still the same, your writing code that can be used in many classes.

maybe you can provide some details about your specific application then we can give you a more specific response.

I think the OP is confused about what exactly we are recommending. It isn’t a “parent” class that you are creating functional characters, pawns, enemies etc from. We are saying create a snip of code that you can call from ANY blueprint you are scripting in. For example, “ForEachLoop” can be called anywhere, “Branch” can be called anywhere, these are “snips” of code that are part of the UE4 standard blueprint macro library. When you want to make something that doesn’t come “standard” with the engine, say a custom bit of code that adds points to your player for killing enemies you can create this and allow it to be called by any blueprint. In order to do that though you have to “script” the logic within some wrapper as part of object oriented programming. This “wrapper” is necessary for back end C++ to function. And now that I think of it the best “wrapper” for your case is an “object”. So you right click in the content browser, look for “blueprint” under the create advanced asset tab, navigate to the expanded menu and you will see “blueprint macro library”. Select that option, then it will ask you for a base class and that is when you select “object”. A macro created with the “object” wrapper will be the most generalizable thing you can make and you can call it from virtually anything you would be getting your hands into.

would I be able to drive the engine Pawn class from “MyMasterActor” class which is a child class of “Actor” class? This way I can sort of add all the new functionality which is inherited by all the actors down the road. Is this recommended ?

Fully aware of how the parent child functions and we are fully using that and that is exactly the issue. How can I drive the character class and actor class from the same class to be able to give them the some shared functionalities ?

I understand the snippet code and macros and am using it across the board but when implementing larger functions that are shared ,isn’t class inheritance the way to go instead of using the same macro everywhere ?

Check out video 15 for an overview an 16 I actually create parent/child BPs in UE4. This covers the basics of class inheritance and what you can do with them. Maybe that is what you are trying to ask?

Ah, that I think requires C++ and you to make your own parent class and then create child classes and try and copy the character and pawn code from the source files. Pretty sure you can’t do what you are asking in blueprints. It would be nice though if you could just make an actor parent and then at some point along the way just have it “inherit” the default character class code.

That’s what ActorComponents are for. Reusable functionalities across different types of actor.

So why not create a new ActorComponent blueprint that will be shared by your MyMasterActor and MyMasterCharacter. So changes you made in your new ActorComponent will reflect to all your actors and their children that uses it.

We have reworked the setups and re structured the classes.