|
- float GetSetVectorX(UObject* ObjectWithVector,FName structname,FName prosFullName )
- {
- FName PropName = structname;//FName("myyy");
- FName VectorMemberName = prosFullName;//FName("aa_4_0592FEC04A8D2B9F467AD3B98BECBF83");
- // float NewValue = 42.0;
- // Get property representing struct
- UProperty* Prop = ObjectWithVector->GetClass()->FindPropertyByName(PropName);
- // Ensure ObjectWithVector actually has a myVector member
- if (Prop)
- {
- // Get struct address
- void* StructAddress = Prop->ContainerPtrToValuePtr<void>(ObjectWithVector);
-
- // Ensure MyVector really is a vector
- if (UStructProperty* StructProp = Cast<UStructProperty>(Prop))
- {
- UE_LOG(LogTemp, Warning, TEXT("struct is %s"), *StructProp->GetName());
- // We'll get struct properties through a UScriptStruct, not a UObject
- // ScriptStructs are just templates and don't hold any of your data
- UScriptStruct* ScriptStruct = StructProp->Struct;
- // Get the vector's "X" property
- UProperty* ChildProp = ScriptStruct->FindPropertyByName(VectorMemberName);
- // Cast to FloatProperty
- if (UFloatProperty* ChildFloatProp = Cast<UFloatProperty>(ChildProp))
- {
- // Get
- // float OldValue = ChildFloatProp->GetFloatingPointPropertyValue(StructAddress);
- float OldValue = ChildFloatProp->GetPropertyValue_InContainer(StructAddress);
- // Set
- //设置变量参数 ChildFloatProp->SetFloatingPointPropertyValue(StructAddress, NewValue);
- return OldValue;
- }
- }
- }
- return 0.13141516;
- }
复制代码
|
|