Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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 ?

Product Version: UE 4.19
more ▼

asked Feb 03 '19 at 01:07 PM in Blueprint Scripting

avatar image

10 3 4 7

avatar image ThompsonN13 Feb 03 '19 at 04:01 PM

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.

avatar image Nebula Games Inc Feb 03 '19 at 04:39 PM

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

avatar image Worldofpolygons Feb 03 '19 at 07:32 PM

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.

avatar image ThompsonN13 Feb 03 '19 at 08:17 PM

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.

avatar image Nebula Games Inc Feb 03 '19 at 08:27 PM

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.

avatar image Worldofpolygons Feb 03 '19 at 09:08 PM

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 ?

avatar image Nebula Games Inc Feb 03 '19 at 09:50 PM

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?


avatar image Worldofpolygons Feb 03 '19 at 11:41 PM

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 ?

avatar image Nebula Games Inc Feb 03 '19 at 11:53 PM

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.

avatar image Chyros Feb 04 '19 at 12:04 PM

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.

avatar image Worldofpolygons Feb 03 '19 at 08:33 PM

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 ?!

Overview of the classes

classes.png (36.4 kB)
avatar image Worldofpolygons Feb 03 '19 at 08:41 PM

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 ?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

We have reworked the setups and re structured the classes.

more ▼

answered Aug 14 '19 at 05:43 AM

avatar image

10 3 4 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question