First of all , i apologize for misleading tittle, because i dont know how to describe it.I just started using unreal engine 4.
I have a player actor which has “Target” actor reference variable. The target variable is changed by gameplay blueprint (selected) and I have enemies called “Enemy 1” , “Enemy 2”.
I want to get variable from actor which is in “Target” Variable.
how i can achieve something like that on bottom?
You will need to cast the “Target” variable to your specific blueprint type which has added the “Max Health” variable.
Right now your “Target” is a regular actor and doesn’t ‘know’ about this variable called “Max Health”.
So drag “Target” to an empty space and type “Cast”, in the short list you should find your “Enemy 1” (or Enemy 2 as seen in screenshot) blueprint class, select this then you can connect the appropriate pins (the blue one on the bottom) to your “Max Health”.
i would want make it automaticaly read the variable when its enemy 1 or enemy 2. enemy 1 and enemy 2 has same variables(variable name) and i want them to be read when they are selected.
at the moment you show how to get variable from specific.
If i do thing what you told me, it will only read max health from Enemy 2
You might want to make a middle man class then, which does practically nothing more than add the “Max Health” variable, then base both Enemy1 and Enemy2 off of this middle class.
Then you just cast to your middle man class whenever you need to get their maximum health (or any other shared variables)
Add health/maxhealth/name variables to this blueprint
Create “EnemyType1” based on this “EnemyBase” blueprint class
Open the “EnemyType1” and set the defaults as desired (different maxhealth values and names)
Whenever you want to get information about this enemy, you can just cast to EnemyBase and you will be able to get their name basehealth/maxhealth values
Optionally you want to add a “BeginPlay” event on your “EnemyBase” class where you set Health to be equal to MaxHealth, this way it will automatically set an enemy to it’s full health potential.
This is an approximation of how blueprint inheritance works with variables: