Get and Set Float/Int by name - C++ correction?…ables-by-name/

Hi, I’ve found this tutorial to create these usefull nodes, which is exactly what I need, a few days ago and tried to reproduce it.
But for some reason “set float/int by name” do not work (“get float/int by name” do work though).
It may work with UE4 4.10 but it does not anymore with latest version :frowning:

Any idea why?
Also, would it be possible to do the same with other types of variables such as string, texture, etc…

Thank you for read and answer :slight_smile:

Alright I found the answer myself (one more time :wink: )
The reason it did not work was because the variable is well set by the “set float/int by name”… but … the actor was not updated because it was set by the construction script before the variable was set by an other actor event.
I could figure out the variable was well set by adding a “get float by name” after a “set float by name”.
Then I had to find a way to force the actor to update. An easy way I found is to toggle its visibility twice… (May be there is an other way with 1 single node?).
Btw it works well now :slight_smile:


The toggle visibility trick was not sufficient in some cases.
Then I had to create a new node I called ReconstructActor (or you can add the code in Set float/int by name nodes but can be not good for optimization). Here is the code for the cpp file :

AActor* UShooterFunctions::ReconstructActor(AActor* InputActor)
    FTransform Pos = InputActor->GetTransform();
    FRotationConversionCache* Rot = 0;
    InputActor->ExecuteConstruction(Pos, Rot, 0, false);
    return InputActor;

I’m not sure about the FRotationConversionCache but I could not find how to get it from my actor, so for now I put 0 and it works.

And I call this node at the end, after I set all my int and floats, and voilà :slight_smile:

It’s worth pointing out that this is an extremely slow method of setting something like a float - and not something you should do often. Everytime you set the value, you are iterating over every possible UPROPERTY in that class and it’s parent classes.

I know, but I need that method for a specific usage :
I make a dynamicActor blueprint + UI to change mesh,material and color of picked actors.
I used a conventionnal method to do so.
I wanted to go a bit further to give the ability to change actor variables.

For example I have a blueprint which generates a Picture Frame (for archviz). In the editor you can change the type of frame, the picture, the size, etc.
And I wanted my dynamicActor to be able to pick this actor (or any other), let the user the ability to set the variable he wants to be dynamic, and, then in game, via the UI, choose between multiple configurations, and update the actor.
This is just an example, but with this method, my dynamicActor is then capable to change any variable of any actor.

I could do this for Int, Float, but also boolean and String.
Now I’d like to do the same for Color, Texture, Material, StaticMesh and LightProfile but I’m stucked because I don’t know what to put instead of UIntProperty and Get and SetPropertyValue_InContainer. I tried UProperty or UObjectProperty but they give errors. What do you think?
The red parts are incorrect.

bool UShooterFunctions::GetColorByName(UObject* Target, FName VarName, FLinearColor& outColor)
    if (Target)
        FLinearColor FoundColor;
      UObjectProperty* ColorProp = FindField<UObjectProperty>(Target->GetClass(), VarName);
        if (ColorProp)
            FoundColor = ColorProp->GetPropertyValuePtr_InContainer(Target);
            outColor = ColorProp;
            return true;
    return false;

FLinearColor would be a UStructProperty. You will have to manually parse all of the structs internal parameters and set them individually. This is really not something you’re meant to do for gameplay code.

If you need to run similar behaviour on objects of different, unrelated classes - use an interface instead.