# Getting variables by name?

**URL:** <https://forums.unrealengine.com/t/getting-variables-by-name/316649>\
**Category:** Plugins\
**Tags:** unreal-engine, editor, Plugins, CPP, question\
**Created:** [April 28, 2015, 12:01am UTC](https://forums.unrealengine.com/t/getting-variables-by-name/316649 "2015-04-28T00:01:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MickD777](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MickD777](https://forums.unrealengine.com/u/MickD777)\
**Post date:** [April 28, 2015, 12:01am UTC](https://forums.unrealengine.com/t/getting-variables-by-name/316649/1 "2015-04-28T00:01:59Z")

</div>

I’m working on an idea to implement a plugin that would need to be able to read all UPROPERTY() declared members of a class. For example, I have a class names AActorTest, that is a child of AActor, with a simple member:

```
UPROPERTY()
int32 aSimpleInt = 0;

```

Is there a way to access all the UPROPERTY() properties in any way, like via the StaticClass? And then get the value of that variable for an instance of that class afterward?

I know this may sound weird, but for my plugin to work the intended way, I would need to do something like this. If anyone has any way to do this (or something similar), let me know!

---

<div class="post-metadata">

**Author:** ![MickD777](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MickD777](https://forums.unrealengine.com/u/MickD777)\
**Post date:** [April 28, 2015, 12:14am UTC](https://forums.unrealengine.com/t/getting-variables-by-name/316649/2 "2015-04-28T00:14:12Z")

</div>

I feel like this as something to do with UProperty\* and UField\*, I’m still searching around but any help is appreciated!

---

<div class="post-metadata">

**Author:** ![marotili](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@marotili](https://forums.unrealengine.com/u/marotili)\
**Post date:** [April 28, 2015, 12:19am UTC](https://forums.unrealengine.com/t/getting-variables-by-name/316649/3 "2015-04-28T00:19:09Z")

</div>

Here you can see how you can iterate over all the properties: [Unreal Property System (Reflection) - Unreal Engine](https://www.unrealengine.com/blog/unreal-property-system-reflection)

Quote:

```
for (TFieldIterator<UProperty> PropIt(GetClass()); PropIt; ++PropIt)
{
UProperty* Property = *PropIt;
// Do something with the property
}

```

You should be able to access the value using “`UProperty::ContainerPtrToValuePtr`” and “`static TPropertyTypeFundamentals::GetPropertyValue`”

You can see an example in `BlueprintNodeHelpers::CollectPropertyDescription`

---

<div class="post-metadata">

**Author:** ![MickD777](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MickD777](https://forums.unrealengine.com/u/MickD777)\
**Post date:** [April 28, 2015, 12:35am UTC](https://forums.unrealengine.com/t/getting-variables-by-name/316649/4 "2015-04-28T00:35:24Z")

</div>

Allright, this is exactly what I needed! I’m still digging around, I also found  
UProperty\* testValueProperty = FindField(GetClass(), “mTestValue”);

that is quite useful for what I want to do. I’m still reading about all this but you’ve been a great help! The reflection page you linked is really great too.

Thanks again!

---

<div class="post-metadata">

**Author:** ![ArCorvus](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ArCorvus](https://forums.unrealengine.com/u/ArCorvus)\
**Post date:** [August 2, 2017, 7:57am UTC](https://forums.unrealengine.com/t/getting-variables-by-name/316649/5 "2017-08-02T07:57:33Z")

</div>

> **[Get / Set variables by Name | Shooter Tutorial](http://shootertutorial.com/2016/03/20/get-set-variables-by-name/)**

---

<div class="post-metadata">

**Author:** ![Philippe23](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Philippe23](https://forums.unrealengine.com/u/Philippe23)\
**Post date:** [March 14, 2018, 8:21pm UTC](https://forums.unrealengine.com/t/getting-variables-by-name/316649/6 "2018-03-14T20:21:48Z")

</div>

In case that tutorial goes away, the gist is:

```
bool UShooterFunctions::GetFloatByName(UObject * Target, FName VarName, float &outFloat)
{
    if (Target) //make sure Target was set in blueprints. 
    {
        float FoundFloat;
        UFloatProperty* FloatProp = FindField<UFloatProperty>(Target->GetClass(), VarName); // try to find float property in Target named VarName
        if (FloatProp) //if we found variable
        {
            FoundFloat = FloatProp->GetPropertyValue_InContainer(Target); // get the value from FloatProp
            outFloat = FoundFloat; // return float
            return true; // we can return
        }
    }
    return false; // we haven't found variable return false
}
```

---

<div class="post-metadata">

**Author:** ![BreakMaker](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/breakmaker/32/971651_2.png) [@BreakMaker](https://forums.unrealengine.com/u/BreakMaker)\
**Post date:** [February 3, 2021, 9:03pm UTC](https://forums.unrealengine.com/t/getting-variables-by-name/316649/7 "2021-02-03T21:03:17Z")

</div>

Do you guys know if this works the same way if I want to get an actor reference which is stored in a variable? So get the actor reference by the variable name essentially. I an actor reference also considered a property?

---

<div class="post-metadata">

**Author:** ![Philippe23](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Philippe23](https://forums.unrealengine.com/u/Philippe23)\
**Post date:** [February 3, 2021, 9:19pm UTC](https://forums.unrealengine.com/t/getting-variables-by-name/316649/8 "2021-02-03T21:19:32Z")

</div>

Should be similar.

I should note that around 4.25 they renamed `UFloatProperty` to `FFloatProperty`.

There’s a `UObjectProperty` / `FObjectProperty` that may be what you need.
