How to communicate between a Player Class and an Actor Class blueprints [UE5]

Hey!
First of all, I’m a beginner at working with UE.
So, I was trying to access a variable in an actor class through a Player class, but it seems not possible when using an object reference.
When I use object reference between two actor classes, I can easily set the instance for the reference object, however, it seems not possible when creating a reference for an actor inside a Player class.
I wonder why it is not possible. What am I doing wrong?

Are you casting properly ?

This is how I’m casting. It says casting is not necessary as the reference is already doing the casting but without this, I get an error.

I’m trying to get a Boolean variable from my Actor and make its value a condition for my Branch in the Player class. The issue is my reference doesn’t update the character value when it changes inside the actor itself. So it always remains False. I wonder what’s the reason for that, but I think having no instance should be the reason why.

This is blueprint of my Player class:

Ok you are already having ref there, cast is not needed. Can you check if you are exposing your variables at damagezone properly ?

What class is your “Damage Zone”?

That´s what you have to cast to. It´s not advisable to directly cast to your object but cast to the parent class and then specify.
To clarify, I made a 4 minute video on the quick basics of casting that should shed some light on this.

I would recommend casting in the sequence slot 0, due to readability and order reasons. You try to get a casted variable state of an actor that get casted after your armor reducing/gaining logic.

Also use the DamageZone casting node for proper errorhandling, then you will instantly know if the cast was succesful or not (child or direct class connection or failure cause not a valid object for that class).

Also number 2: If you want to bottleneck your OnTick Event do it before the sequence. Or create a custom event with an own repeating pattern you’ll then just initialize at BeginPlay. (Or loop it on begin play)

Also number 3: Your created a variable of an object reference of DamageZone. You did’nt assign a default value therefore you have to assign it somewhere else or otherwise it will be an empty reference. (Didn’t get that info out of your post, sorry I’m just quickly stopping by)

regards
wefl aka Ralf

My DamageZone class is Actor. and My Third-Person Character class is Character.

So I changed DamageZoneRef from Object Reference to an Actor Reference. But the issue is still there. I still can’t set an instance to my reference, and I get the following error:

“PIE: Error: Blueprint Runtime Error: “Accessed None trying to read property K2Node_DynamicCast_AsDamage_Zone”. Node: Branch Graph: EventGraph Function: Execute Ubergraph BP Third Person Character Blueprint: BP_ThirdPersonCharacter”

Here is my DamageZone blueprint:

By the way, here is how my casting looks like now (I get the Cast Fail print):

No.3: That’s the real problem. It doesn’t allow me to set an instance for the reference object.
Also, thanks for your first tip. I didn’t know about that.

You are actually doing a redundant call for similar actions.
why arent you just using your 5% function which you already call while overlapping to initiate a custom event instead of a bottlenecked tick event?
Even if your are using different tick intervalls for your damage and armor. If I’m understanding your design correctly you differentiate between them two, right?

Otherwise if you want to keep your logic - In your overlapping event of the zone you are casting to the player character. You can there access the zone variable within your character and store “self”-reference inside (just set variable with self). This will fill your object reference.

Yes. I want the armor to get the damage first, when the armor reaches 0, DamageZone starts affecting Health. When you get out of DamageZone, your Health remains untouched but your Armor regenerates.
So, my issue is the fact that when I’m getting damage to my Armor, in the meantime, it regenerates as well.
So, I want to use the “is in damage” Bool to stop regeneration when taking damage. That’s why I try to get a reference to DamageZone from my Character class to read the “is in damage” value, which is why I had put the casting into an Event Tick to check it regularly.
But every time, my casting fails because it doesn’t allow me to set an instance for my reference.
The method you mentioned will defienetly optimize my Blueprint, but if I’m not mistaken, it will still require a casting to my Damage Zone from my character, which requires a reference. So i have to deal with the same unsolved issue.

As already stated in my last paragraph.
You can access and set the zone reference after casting to your character within your zone blueprint.
Just take the character object of the cast and type set zone and select the right variable then just assign self to it.

Edit:
I’m currently ar gym so not able to think through out a best practice solution. Tho I would recommend handling the overlapping character side. So you store the zones you overkap in the character directly when you overlap them. Easiest and simplest setup imo.
You are currently handling the overlap at the zone. Its also way more dynamically configurable when you handle it characterwise, thinking of different zone types.

So, I finally managed to solve it with a workaround.
Rather than using an Object or Actor Reference, I tried using a Class Reference to DamageZone, and it finally allowed me to set an instance for this Class Reference. Then I used Get Class Actor to access “is in damage” and the code finally worked properly as I wanted it to work.
The fun part is after defining a Class Reference when I defined an additional Object Reference it worked too, allowing me to choose an instance for the object. But as soon as I remove Class Reference, Object Reference loses the instance. Still can’t figure out why is this happening (as far as my almost zero knowledge of UE goes) but I can temporarily move forward I think.

Also, your point on placing the overlapping process on Character side is absolutely correct. I need to change it.