x

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"

Get variable by name(?)

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? alt text

Note: im not asking why it wont allow connect , i just wanted to show how i want it look like.

Product Version: UE 4.9
Tags:
var.png (65.8 kB)
more ▼

asked Oct 25 '15 at 03:01 PM in Blueprint Scripting

avatar image

terrio
8 1 2 4

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

2 answers: sort voted first

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".

more ▼

answered Oct 25 '15 at 03:31 PM

avatar image

Red15
57 1 6 7

avatar image terrio Oct 25 '15 at 04:10 PM

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

avatar image Red15 Oct 25 '15 at 04:19 PM

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)

avatar image terrio Oct 25 '15 at 04:25 PM

so i have to create a blue print which changes his variable equal to enemy 1 or enemy 2 max health when selected ?

avatar image Red15 Oct 25 '15 at 04:28 PM

This is hard for me to estimate as I'm not entirely sure what you're trying to achieve gameplay-wise.

avatar image terrio Oct 25 '15 at 04:29 PM

atm i want to show "Target" name ,max health / health on hud. i dont want to create new casts every enemy type i have

avatar image Red15 Oct 25 '15 at 04:41 PM

So you do as I have described:

  1. Create a common "EnemyBase" blueprint

  2. Add health/maxhealth/name variables to this blueprint

  3. Create "EnemyType1" based on this "EnemyBase" blueprint class

  4. Open the "EnemyType1" and set the defaults as desired (different maxhealth values and names)

  5. 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: alt text

avatar image terrio Oct 25 '15 at 05:14 PM

im confused at

then base both Enemy1 and Enemy2 off of this middle class

, how i can get variable from Enemy1 using EnemyBase, have i use blueprints or there are settings in this

avatar image Red15 Oct 25 '15 at 05:30 PM

Because every Enemy1 is also an EnemyBase.

Here is a quick video where I show how I create inherited EnemyTypes which all have the MaxHealth variable (but each type can have it's own default)

I do this in a couple of ways to demonstrate how you can change a blueprint's parent:

  1. Create child blueprint via right click on EnemyBase in content browser

  2. Create a new blueprint and select EnemyBase as it's base by searching for its name

  3. Create a new blueprint of actor type and changing it's parent by going to the class settings

https://youtu.be/2NpeHVc81Nw

avatar image terrio Oct 25 '15 at 05:49 PM

works like charm thx

avatar image Red15 Oct 25 '15 at 06:20 PM

Sorry I seem to have edited the post which you accepted as answer (youtube link instead of onedrive) and now the answer status has reverted ...

(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