Hello,
could someone tell me how I can set a bp variable with c++?
using UE reflection system :
bool SetFloatByName(UObject * Target, FName VarName)
{
UFloatProperty* FloatProp = FindField<UFloatProperty>(Target->GetClass(), VarName);
if (FloatProp)
{
FloatProp->SetPropertyValue_InContainer(Target, NewValue);
return true;
}
return false;
}
you have Bool/Float/Int/Object Properties classes availliable, choose the one you need
Using reflection is expensive, so avoid it as much as possible, especially in hot paths, ( you can also cache fields )
Do you know what the best way is to get a value that has been calculated via c++ in my anim bp?
Sure, make a new class based on “UAnimInstance” ( cpp name base class of Animation blueprint)
ex:
class YOURGAME_API UBaseEnemiesAnimBlueprint : public UAnimInstance
{
virtual void NativeInitializeAnimation() override; //BeginPlay
virtual void NativeUpdateAnimation(float DeltaTimeX) override; //Tick
//
// velocity
//
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Data)
float Speed;
}
and reparent your animation blueprint on that. so you can have a shared base with variable for all your units and just the differences added on top in blueprint
Uproperties taged with “BlueprintReadWrite” will be readable in animation blueprint