UE4C++读取设置蓝图变量(备忘)

读取:

bool UShooterFunctions::GetFloatByName(UObject * Target, FName VarName, float &outFloat)

{

    if (Target) //make sure Target was set in blueprints.

    {

        float FoundFloat;

        UFloatProperty* FloatProp = FindField(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

}

 

写入:

bool UShooterFunctions::SetFloatByName(UObject * Target, FName VarName, float NewValue, float & outFloat)

{

    if (Target)

    {

        float FoundFloat;

        UFloatProperty* FloatProp = FindField(Target->GetClass(), VarName);

        if (FloatProp)

        {

            FloatProp->SetPropertyValue_InContainer(Target, NewValue); //this actually sets the variable

            FoundFloat = FloatProp->GetPropertyValue_InContainer(Target);

            outFloat = FoundFloat;

            return true;

        }

    }

    return false;

}

 

地址:How to access blueprint vars in c++?:https://answers.unrealengine.com/questions/2145/how-to-access-blueprint-vars-in-c.html

 

 

你可能感兴趣的:(UE4学习,UE4,c++,读写,蓝图)