How tf do I get Blueprints to communicate with each other?!

So here’s the summary of what it is I’m trying to do.

The player character has a few health states, for example:

Healthy: 0
Hurt: 1

I set up a MedKit, which works on charges (Max 2 Charges). To heal oneself, it costs 2 charges, and to heal an ally it costs 1 charge.

However, this was all housed within the Player Character blueprint. Which isn’t the right way to go about things like this right? (I’m quite new to the engine, this is one of my first attempts to do something without any tutorial)

This is because I want the ability for the Player Character to be allowed to drop the item they are holding, or for it to be knocked out of their hands, and this specific item needs to retain its individual charges even with multiple of the same item present.

My issue is that when setting up a MedKit actor which keeps track of the medkits info such as charges, I cannot get the Player Character blueprint to “talk” to the MedKit blueprint to check how many charges it has, and to tell the MedKit to remove the required amount of charges once the health state has been set.

I’ve tried event dispatchers and interfaces, but I cannot get these to function, maybe I am setting them up wrong? Any advice or examples would be incredible.

P.S
I’ve watched dozens of YouTube tutorials about this, but practically all of them involve using Bounds to check for overlaps, which feeds into the Event Dispatcher.

I think ideally, you would put all that stuff you showed in the image, inside the medkit actor’s blueprint.

Then you can call these events from anywhere you like, as long as you have a reference to the medkit actor.

There are various ways to obtain a reference to the medkit actor. Most people would probably use the overlap events system to get that reference though.

Aye this was my thought process too.

I’ve put all of this into the medkit actor bp, my issue is that I cannot for the life of me figure out how to trigger the logic inside the medkit BP FROM the player character BP.

Using event dispatchers and interfaces do not seem to work, I’m not sure if I am setting them up incorrectly.

Using the overlap isn’t needed here as the medkit is only a physical object when it is laying on the floor, once picked up it’s just a “HasMedkit?” variable.

Is it that you are not familiar with casting?
In order to access the function in the “other actor” that the overlap event provides, you first need to cast “other actor” to your medkit actor class.

I’ve been trying to avoid Cast To (thing here) as much as possible because I’ve been told that hard references are bad and inefficient.

Is this a case where I should use Cast To?

But also, I’m not using any overlaps here as it’s not a physical object in the world which is touching or nearby the player character. It’s a held item so it’s just became a variable. Is this wrong?

you dont have to use overlap events, if you already have a reference to the object.
Overlap events are just a handy way to obtain a reference to an object when you get near to said object.

I don’t feel very qualified to advise regarding hard references. If your project is small, they are not a problem.

If it is big, you may want to look into interfaces, they can help you to minimize the amount of casting you do.

I’ll have another stab setting up some object references and see if anything happens.

Okay so,
image

In these two screenshots, I set up a BP Interface for items to try and make the bridge between the PlayerBP and the MedkitBP, I thought in theory this should work however on runtime I am getting an “Accessed None trying to read property MedKitRef”. The medkitref is an object reference to the MedKitBP.

What do you think I should do?

Thats means the medkit variable has not been set to reference an instance of the actor. Currently it is empty/null. It needs to be set somewhow.

In this situation, how would you go about referencing the actor, specifically an instance of it? Thank you :slight_smile:

I dont know what’s best for your situation, but I know using an overlap event would work.

Alternatively, if you use the “spawn actor from class” node to spawn a medkit, that would also give you a reference to the spawned actor.

I see,

what I am failing to understand is that, say for example I spawn a MedKit object on the floor, the player can walk to this and pick it up, in that case, the variable “HasMedkit?” would be made true, then that object would be destroyed so that it is no longer on the floor.

This would invalidate the object reference right?

When the MedKit becomes something that is not its own object anymore, how do call information from the blueprint when all methods of communicating to other blueprints require an object reference?

oh I see.
A dirty way to fix that, would be to not destroy the medkit actor. Instead you could disable it so it can no longer be seen by the camera or physics system.

Alternatively, you could store medkit data inside structs, instead of inside the medkit actors, but taht makes thinks a little more complex.

I’ll see if that works!

Okay so!

I’ve set it up so when stepping in the radius of a MedKit BPs bounds (a temporary way of saying “I have a medkit now”, it references itself the MedKitRef. Same for an Ally as the Ally now has a “Nearby Ally” object reference.

However, if I attempt to heal before having a medkit, it is giving me Null reference errors in the BP. Is this normal? The code to my knowledge is functioning the way I want, but it’s giving errors once I close the runtime instance.

Not sure I understand, but if you want to check whether the medkit variable is null, you can use this node
image

Im afraid I cant help you with all these specifics as this isn’t my area of expertise and I don’t fully understand how your system works.