Download

Communication between BluePrints

Pretty new to UE4 and all that. Been doing some BluePrint-ing to try it out and it’s pretty logical. Like any language you don’t know fluently, you know what you want to say but not exactly how to say it.

Made a cube that chases me down and which I can destroy by shooting it. It also drops items now and then, 30% chance for an item to drop.

I feel like I should extract some of my BP-code to be universal for a type of object(?). I mean, if I make new enemies then I don’t want to have a drop function in every single one but rather one drop function that I call for whatever item that drops. Every item has its own drop rate.

My thinking was to make a pawn with things in common for every item and from that pawn create new children. Something like:
Item

  • Orange
  • Apple

Item having a drop function which return a boolean if it should drop.
The child having a variable that’s drop rate which modifies the drop function in item.

So when my cube is destroyed (or right before), it might drop an Apple. Before the cube is destroyed, it asks the Apple if it will drop, the Apple ask the Item “Hey Item! I have a 30% chance to drop, will I drop?”, then the Item respond to the Apple saying “Yeah, why not? Do drop” and the Apple tells the cube that yes, it will drop. The cube dies (gets destroyed) happily.

First question, is this the right line of thinking? I really like the concept of DRY (Don’t Repeat Yourself) and figured that if something repeats within different BP then they should be abstracted to something above, like a parent.

Second question, how do I communicate between BP? I’m trying to run my drop function but I don’t seem to be able to reference it.

Been browsing around a bit trying to figure it out with casts etc but I have not found anything helping me with the above. Hence starting to questioning if I’m even thinking in the right direction.
Thankful for any help or pointers :slight_smile:

You’re going down the right path. Just need to modularize it a bit more. Have a parent class for items that can be dropped and an Actor Component class that you add to Pawns that handles the logic of when, what and If they can drop something. All the logic of dropping something will be in the Actor component. Simply add this to all your enemy pawns and configure it.

  • Can I drop something (Bool)
  • Have I already dropped something (Bool)
  • When can I drop (float, health comparison)
  • What can I drop (enum list, or array, or struct etc)

In the pawn (enemy) you reference the actor component -> Custom Event: Can I drop -> Yes: Have I dropped -> No: When can I drop (health comparison) -> what can I drop, do it, set HasDropped? true.

I suggest you check out the following channels:

I also made a video about communicating between blueprints with Blueprint Interfaces: