void UDeveloperSettings::ExportValuesToConsoleVariables(UProperty* PropertyThatChanged) { check(PropertyThatChanged); FString CVarName = PropertyThatChanged->GetMetaData(DeveloperSettingsConsoleVariableMetaFName); if (!CVarName.IsEmpty()) { IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(*CVarName); if (CVar && (CVar->GetFlags() & ECVF_ReadOnly) == 0) { UByteProperty* ByteProperty = Cast<UByteProperty>(PropertyThatChanged); if (ByteProperty != NULL && ByteProperty->Enum != NULL) { CVar->Set(ByteProperty->GetPropertyValue_InContainer(this), ECVF_SetByProjectSetting); } else if (UBoolProperty* BoolProperty = Cast<UBoolProperty>(PropertyThatChanged)) { CVar->Set((int32)BoolProperty->GetPropertyValue_InContainer(this), ECVF_SetByProjectSetting); } else if (UIntProperty* IntProperty = Cast<UIntProperty>(PropertyThatChanged)) { CVar->Set(IntProperty->GetPropertyValue_InContainer(this), ECVF_SetByProjectSetting); } else if (UFloatProperty* FloatProperty = Cast<UFloatProperty>(PropertyThatChanged)) { CVar->Set(FloatProperty->GetPropertyValue_InContainer(this), ECVF_SetByProjectSetting); } } else { UE_LOG(LogInit, Warning, TEXT("CVar named '%s' marked up in %s was not found or is set to read-only"), *CVarName, *GetClass()->GetName()); } } }
static void SetPropertyValue( UObject *Target, const FString &PropertyName, const FString &PropertyValue ) { if ( Target == NULL ) return; void *ContainerPtr = Target; int32 ArrayIndex; UProperty *Prop = nLiveEditorListenServer::GetPropertyByName( Target, Target->GetClass(), PropertyName, &ContainerPtr, ArrayIndex ); if ( !Prop || !Prop->IsA( UNumericProperty::StaticClass() ) ) { return; } check( ContainerPtr != NULL ); if ( Prop->IsA( UByteProperty::StaticClass() ) ) { UByteProperty *NumericProp = CastChecked<UByteProperty>(Prop); uint8 Value = FCString::Atoi( *PropertyValue ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex); } else if ( Prop->IsA( UInt8Property::StaticClass() ) ) { UInt8Property *NumericProp = CastChecked<UInt8Property>(Prop); int32 Value = FCString::Atoi( *PropertyValue ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex); } else if ( Prop->IsA( UInt16Property::StaticClass() ) ) { UInt16Property *NumericProp = CastChecked<UInt16Property>(Prop); int16 Value = FCString::Atoi( *PropertyValue ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex); } else if ( Prop->IsA( UIntProperty::StaticClass() ) ) { UIntProperty *NumericProp = CastChecked<UIntProperty>(Prop); int32 Value = FCString::Atoi( *PropertyValue ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex); } else if ( Prop->IsA( UInt64Property::StaticClass() ) ) { UInt64Property *NumericProp = CastChecked<UInt64Property>(Prop); int64 Value = FCString::Atoi64( *PropertyValue ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex); } else if ( Prop->IsA( UUInt16Property::StaticClass() ) ) { UUInt16Property *NumericProp = CastChecked<UUInt16Property>(Prop); uint16 Value = FCString::Atoi( *PropertyValue ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex); } else if ( Prop->IsA( UUInt32Property::StaticClass() ) ) { UUInt32Property *NumericProp = CastChecked<UUInt32Property>(Prop); uint32 Value = FCString::Atoi( *PropertyValue ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex); } else if ( Prop->IsA( UInt64Property::StaticClass() ) ) { UInt64Property *NumericProp = CastChecked<UInt64Property>(Prop); uint64 Value = FCString::Atoi64( *PropertyValue ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex); } else if ( Prop->IsA( UFloatProperty::StaticClass() ) ) { UFloatProperty *NumericProp = CastChecked<UFloatProperty>(Prop); float Value = FCString::Atof( *PropertyValue ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex); } else if ( Prop->IsA( UDoubleProperty::StaticClass() ) ) { UDoubleProperty *NumericProp = CastChecked<UDoubleProperty>(Prop); double Value = FCString::Atod( *PropertyValue ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, Value, ArrayIndex); } }
void FCEFJSStructSerializerBackend::WriteProperty(const FStructSerializerState& State, int32 ArrayIndex) { // booleans if (State.ValueType == UBoolProperty::StaticClass()) { Add(State, Cast<UBoolProperty>(State.ValueProperty)->GetPropertyValue_InContainer(State.ValueData, ArrayIndex)); } // unsigned bytes & enumerations else if (State.ValueType == UByteProperty::StaticClass()) { UByteProperty* ByteProperty = Cast<UByteProperty>(State.ValueProperty); if (ByteProperty->IsEnum()) { Add(State, ByteProperty->Enum->GetEnumName(ByteProperty->GetPropertyValue_InContainer(State.ValueData, ArrayIndex))); } else { Add(State, (double)Cast<UByteProperty>(State.ValueProperty)->GetPropertyValue_InContainer(State.ValueData, ArrayIndex)); } } // floating point numbers else if (State.ValueType == UDoubleProperty::StaticClass()) { Add(State, Cast<UDoubleProperty>(State.ValueProperty)->GetPropertyValue_InContainer(State.ValueData, ArrayIndex)); } else if (State.ValueType == UFloatProperty::StaticClass()) { Add(State, Cast<UFloatProperty>(State.ValueProperty)->GetPropertyValue_InContainer(State.ValueData, ArrayIndex)); } // signed integers else if (State.ValueType == UIntProperty::StaticClass()) { Add(State, (int32)Cast<UIntProperty>(State.ValueProperty)->GetPropertyValue_InContainer(State.ValueData, ArrayIndex)); } else if (State.ValueType == UInt8Property::StaticClass()) { Add(State, (int32)Cast<UInt8Property>(State.ValueProperty)->GetPropertyValue_InContainer(State.ValueData, ArrayIndex)); } else if (State.ValueType == UInt16Property::StaticClass()) { Add(State, (int32)Cast<UInt16Property>(State.ValueProperty)->GetPropertyValue_InContainer(State.ValueData, ArrayIndex)); } else if (State.ValueType == UInt64Property::StaticClass()) { Add(State, (double)Cast<UInt64Property>(State.ValueProperty)->GetPropertyValue_InContainer(State.ValueData, ArrayIndex)); } // unsigned integers else if (State.ValueType == UUInt16Property::StaticClass()) { Add(State, (int32)Cast<UUInt16Property>(State.ValueProperty)->GetPropertyValue_InContainer(State.ValueData, ArrayIndex)); } else if (State.ValueType == UUInt32Property::StaticClass()) { Add(State, (double)Cast<UUInt32Property>(State.ValueProperty)->GetPropertyValue_InContainer(State.ValueData, ArrayIndex)); } else if (State.ValueType == UUInt64Property::StaticClass()) { Add(State, (double)Cast<UUInt64Property>(State.ValueProperty)->GetPropertyValue_InContainer(State.ValueData, ArrayIndex)); } // names & strings else if (State.ValueType == UNameProperty::StaticClass()) { Add(State, Cast<UNameProperty>(State.ValueProperty)->GetPropertyValue_InContainer(State.ValueData, ArrayIndex).ToString()); } else if (State.ValueType == UStrProperty::StaticClass()) { Add(State, Cast<UStrProperty>(State.ValueProperty)->GetPropertyValue_InContainer(State.ValueData, ArrayIndex)); } else if (State.ValueType == UTextProperty::StaticClass()) { Add(State, Cast<UTextProperty>(State.ValueProperty)->GetPropertyValue_InContainer(State.ValueData, ArrayIndex).ToString()); } // classes & objects else if (State.ValueType == UClassProperty::StaticClass()) { Add(State, Cast<UClassProperty>(State.ValueProperty)->GetPropertyValue_InContainer(State.ValueData, ArrayIndex)->GetPathName()); } else if (State.ValueType == UObjectProperty::StaticClass()) { Add(State, Cast<UObjectProperty>(State.ValueProperty)->GetPropertyValue_InContainer(State.ValueData, ArrayIndex)); } // unsupported property type else { GLog->Logf(ELogVerbosity::Warning, TEXT("FCEFJSStructSerializerBackend: Property %s cannot be serialized, because its type (%s) is not supported"), *State.ValueProperty->GetName(), *State.ValueType->GetName()); } }
FWebJSParam FWebJSScripting::ConvertResult(UProperty* Property, uint8* Data) { // booleans if (Property->IsA<UBoolProperty>()) { return FWebJSParam(Cast<UBoolProperty>(Property)->GetPropertyValue_InContainer(Data)); } // unsigned bytes & enumerations else if (Property->IsA<UByteProperty>()) { UByteProperty* ByteProperty = Cast<UByteProperty>(Property); if (ByteProperty->IsEnum()) { return FWebJSParam(ByteProperty->Enum->GetEnumName(ByteProperty->GetPropertyValue_InContainer(Data))); } else { return FWebJSParam((int32)ByteProperty->GetPropertyValue_InContainer(Data)); } } // floating point numbers else if (Property->IsA<UDoubleProperty>()) { return FWebJSParam(Cast<UDoubleProperty>(Property)->GetPropertyValue_InContainer(Data)); } else if (Property->IsA<UFloatProperty>()) { return FWebJSParam(Cast<UFloatProperty>(Property)->GetPropertyValue_InContainer(Data)); } // signed integers else if (Property->IsA<UIntProperty>()) { return FWebJSParam(Cast<UIntProperty>(Property)->GetPropertyValue_InContainer(Data)); } else if (Property->IsA<UInt8Property>()) { return FWebJSParam((int32)Cast<UInt8Property>(Property)->GetPropertyValue_InContainer(Data)); } else if (Property->IsA<UInt16Property>()) { return FWebJSParam((int32)Cast<UInt16Property>(Property)->GetPropertyValue_InContainer(Data)); } else if (Property->IsA<UInt64Property>()) { return FWebJSParam((double)Cast<UInt64Property>(Property)->GetPropertyValue_InContainer(Data)); } // unsigned integers else if (Property->IsA<UUInt16Property>()) { return FWebJSParam((int32)Cast<UUInt16Property>(Property)->GetPropertyValue_InContainer(Data)); } else if (Property->IsA<UUInt32Property>()) { return FWebJSParam((double)Cast<UUInt32Property>(Property)->GetPropertyValue_InContainer(Data)); } else if (Property->IsA<UUInt64Property>()) { return FWebJSParam((double)Cast<UUInt64Property>(Property)->GetPropertyValue_InContainer(Data)); } // names & strings else if (Property->IsA<UNameProperty>()) { return FWebJSParam(Cast<UNameProperty>(Property)->GetPropertyValue_InContainer(Data).ToString()); } else if (Property->IsA<UStrProperty>()) { return FWebJSParam(Cast<UStrProperty>(Property)->GetPropertyValue_InContainer(Data)); } // classes & objects else if (Property->IsA<UClassProperty>()) { return FWebJSParam(Cast<UClassProperty>(Property)->GetPropertyValue_InContainer(Data)->GetPathName()); } else if (Property->IsA<UObjectProperty>()) { return FWebJSParam(Cast<UObjectProperty>(Property)->GetPropertyValue_InContainer(Data)); } else if (Property->IsA<UStructProperty>()) { UStructProperty* StructProperty = Cast<UStructProperty>(Property); return FWebJSParam(StructProperty->Struct, StructProperty->ContainerPtrToValuePtr<void>(Data)); } else { GLog->Logf(ELogVerbosity::Warning, TEXT("FWebJSScripting: %s cannot be serialized, because its type (%s) is not supported"), *Property->GetName(), *Property->GetClass()->GetName()); } return FWebJSParam(); }
static void CopyPropertyFromArchetype( UObject *Target, UObject *Archetype, FName PropertyName ) { if ( Target == NULL || Archetype == NULL || !Target->IsA( Archetype->GetClass() ) ) return; void *ArchetypeContainerPtr = Archetype; int32 ArchetypeArrayIndex; UProperty *Prop = GetPropertyByName( Archetype, Archetype->GetClass(), PropertyName.ToString(), &ArchetypeContainerPtr, ArchetypeArrayIndex ); if ( !Prop || !Prop->IsA( UNumericProperty::StaticClass() ) ) return; check(ArchetypeContainerPtr != NULL); void *TargetContainerPtr = Target; //(void*)((uint8*)ArchetypeContainerPtr - (uint8*)Archetype + (uint8*)Target); int32 TargetArrayIndex; UProperty *TargetProp = GetPropertyByName( Target, Target->GetClass(), PropertyName.ToString(), &TargetContainerPtr, TargetArrayIndex ); check( TargetProp != NULL && TargetProp->IsA( UNumericProperty::StaticClass() ) ); check( TargetArrayIndex == ArchetypeArrayIndex ); if ( Prop->IsA( UByteProperty::StaticClass() ) ) { UByteProperty *NumericProp = CastChecked<UByteProperty>(Prop); uint8 ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex); NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex); } else if ( Prop->IsA( UInt8Property::StaticClass() ) ) { UInt8Property *NumericProp = CastChecked<UInt8Property>(Prop); int32 ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex); NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex); } else if ( Prop->IsA( UInt16Property::StaticClass() ) ) { UInt16Property *NumericProp = CastChecked<UInt16Property>(Prop); int16 ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex); NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex); } else if ( Prop->IsA( UIntProperty::StaticClass() ) ) { UIntProperty *NumericProp = CastChecked<UIntProperty>(Prop); int32 ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex); NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex); } else if ( Prop->IsA( UInt64Property::StaticClass() ) ) { UInt64Property *NumericProp = CastChecked<UInt64Property>(Prop); int64 ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex); NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex); } else if ( Prop->IsA( UUInt16Property::StaticClass() ) ) { UUInt16Property *NumericProp = CastChecked<UUInt16Property>(Prop); uint16 ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex); NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex); } else if ( Prop->IsA( UUInt32Property::StaticClass() ) ) { UUInt32Property *NumericProp = CastChecked<UUInt32Property>(Prop); uint32 ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex); NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex); } else if ( Prop->IsA( UInt64Property::StaticClass() ) ) { UInt64Property *NumericProp = CastChecked<UInt64Property>(Prop); uint64 ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex); NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex); } else if ( Prop->IsA( UFloatProperty::StaticClass() ) ) { UFloatProperty *NumericProp = CastChecked<UFloatProperty>(Prop); float ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex); NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex); } else if ( Prop->IsA( UDoubleProperty::StaticClass() ) ) { UDoubleProperty *NumericProp = CastChecked<UDoubleProperty>(Prop); double ArchetypeVal = NumericProp->GetPropertyValue_InContainer(ArchetypeContainerPtr, ArchetypeArrayIndex); NumericProp->SetPropertyValue_InContainer(TargetContainerPtr, ArchetypeVal, ArchetypeArrayIndex); } }
static void ModifyPropertyValue( UObject *Target, const FString &PropertyName, TEnumAsByte<ELiveEditControllerType::Type> ControlType, float Delta, int32 MidiValue, bool bShouldClamp, float ClampMin, float ClampMax ) { if ( Target == NULL ) return; void *ContainerPtr = Target; int32 ArrayIndex = 0; UProperty *Prop = GetPropertyByName( Target, Target->GetClass(), PropertyName, &ContainerPtr, ArrayIndex ); if ( Prop == NULL || !Prop->IsA( UNumericProperty::StaticClass() ) ) return; check( ContainerPtr != NULL ); if ( bShouldClamp && ControlType == ELiveEditControllerType::ControlChangeFixed ) { //if we are clamped and it's a fixed range controller, make sure that the Delta can cover the full span of the clamped range //this overrides DeltaMult on the LiveEditObject Action in the case where DeltaMult is too small to cover the clamped range //with the meager fidelity of Midi (127 ticks per controller) float EvenDelta = (ClampMax - ClampMin)/127.0f; if ( EvenDelta > FMath::Abs(Delta) ) { float sign = (Delta > 0.0f)? 1.0f : -1.0f; Delta = EvenDelta * sign; } } if ( Prop->IsA( UByteProperty::StaticClass() ) ) { UByteProperty *NumericProp = CastChecked<UByteProperty>(Prop); uint8 CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex); uint8 NewValue = CalculateNewValue<uint8>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex); } else if ( Prop->IsA( UInt8Property::StaticClass() ) ) { UInt8Property *NumericProp = CastChecked<UInt8Property>(Prop); uint8 CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex); uint8 NewValue = CalculateNewValue<uint8>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex); } else if ( Prop->IsA( UInt16Property::StaticClass() ) ) { UInt16Property *NumericProp = CastChecked<UInt16Property>(Prop); int16 CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex); int16 NewValue = CalculateNewValue<int16>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex); } else if ( Prop->IsA( UIntProperty::StaticClass() ) ) { UIntProperty *NumericProp = CastChecked<UIntProperty>(Prop); int32 CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex); int32 NewValue = CalculateNewValue<int32>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex); } else if ( Prop->IsA( UInt64Property::StaticClass() ) ) { UInt64Property *NumericProp = CastChecked<UInt64Property>(Prop); int64 CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex); int64 NewValue = CalculateNewValue<int64>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex); } else if ( Prop->IsA( UUInt16Property::StaticClass() ) ) { UUInt16Property *NumericProp = CastChecked<UUInt16Property>(Prop); uint16 CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex); uint16 NewValue = CalculateNewValue<uint16>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex); } else if ( Prop->IsA( UUInt32Property::StaticClass() ) ) { UUInt32Property *NumericProp = CastChecked<UUInt32Property>(Prop); uint32 CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex); uint32 NewValue = CalculateNewValue<uint32>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex); } else if ( Prop->IsA( UInt64Property::StaticClass() ) ) { UInt64Property *NumericProp = CastChecked<UInt64Property>(Prop); uint64 CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex); uint64 NewValue = CalculateNewValue<uint64>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex); } else if ( Prop->IsA( UFloatProperty::StaticClass() ) ) { UFloatProperty *NumericProp = CastChecked<UFloatProperty>(Prop); float CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex); float NewValue = CalculateNewValue<float>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex); } else if ( Prop->IsA( UDoubleProperty::StaticClass() ) ) { UDoubleProperty *NumericProp = CastChecked<UDoubleProperty>(Prop); double CurValue = NumericProp->GetPropertyValue_InContainer(ContainerPtr, ArrayIndex); double NewValue = CalculateNewValue<double>( CurValue, ControlType, Delta, MidiValue, bShouldClamp, ClampMin, ClampMax ); NumericProp->SetPropertyValue_InContainer(ContainerPtr, NewValue, ArrayIndex); } }