void UDeveloperSettings::ImportConsoleVariableValues() { for (UProperty* Property = GetClass()->PropertyLink; Property; Property = Property->PropertyLinkNext) { if (!Property->HasAnyPropertyFlags(CPF_Config)) { continue; } FString CVarName = Property->GetMetaData(DeveloperSettingsConsoleVariableMetaFName); if (!CVarName.IsEmpty()) { IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(*CVarName); if (CVar) { if (Property->ImportText(*CVar->GetString(), Property->ContainerPtrToValuePtr<uint8>(this, 0), PPF_ConsoleVariable, this) == NULL) { UE_LOG(LogTemp, Error, TEXT("%s import failed for %s on console variable %s (=%s)"), *GetClass()->GetName(), *Property->GetName(), *CVarName, *CVar->GetString()); } } else { UE_LOG(LogTemp, Fatal, TEXT("%s failed to find console variable %s for %s"), *GetClass()->GetName(), *CVarName, *Property->GetName()); } } } }
/** * Applies settings to an object by finding UProperties by name and calling ImportText * * @param InObject - The object to search for matching properties * @param PropertyChain - The list UProperty names recursively to search through * @param Value - The value to import on the found property */ void ApplyCustomFactorySetting(UObject* InObject, TArray<FString>& PropertyChain, const FString& Value) { const FString PropertyName = PropertyChain[0]; PropertyChain.RemoveAt(0); UProperty* TargetProperty = FindField<UProperty>(InObject->GetClass(), *PropertyName); if (TargetProperty) { if (PropertyChain.Num() == 0) { TargetProperty->ImportText(*Value, TargetProperty->ContainerPtrToValuePtr<uint8>(InObject), 0, InObject); } else { UStructProperty* StructProperty = Cast<UStructProperty>(TargetProperty); UObjectProperty* ObjectProperty = Cast<UObjectProperty>(TargetProperty); UObject* SubObject = NULL; bool bValidPropertyType = true; if (StructProperty) { SubObject = StructProperty->Struct; } else if (ObjectProperty) { SubObject = ObjectProperty->GetObjectPropertyValue(ObjectProperty->ContainerPtrToValuePtr<UObject>(InObject)); } else { //Unknown nested object type bValidPropertyType = false; UE_LOG(LogAutomationEditorCommon, Error, TEXT("ERROR: Unknown nested object type for property: %s"), *PropertyName); } if (SubObject) { ApplyCustomFactorySetting(SubObject, PropertyChain, Value); } else if (bValidPropertyType) { UE_LOG(LogAutomationEditorCommon, Error, TEXT("Error accessing null property: %s"), *PropertyName); } } } else { UE_LOG(LogAutomationEditorCommon, Error, TEXT("ERROR: Could not find factory property: %s"), *PropertyName); } }
/** * Sets an object property value by name * @param TargetObject - The object to modify * @param InVariableName - The name of the property */ void SetPropertyByName(UObject* TargetObject, const FString& InVariableName, const FString& NewValueString) { UProperty* FoundProperty = FindField<UProperty>(TargetObject->GetClass(), *InVariableName); if (FoundProperty) { const FScopedTransaction PropertyChanged(LOCTEXT("PropertyChanged", "Object Property Change")); TargetObject->Modify(); TargetObject->PreEditChange(FoundProperty); FoundProperty->ImportText(*NewValueString, FoundProperty->ContainerPtrToValuePtr<uint8>(TargetObject), 0, TargetObject); FPropertyChangedEvent PropertyChangedEvent(FoundProperty, EPropertyChangeType::ValueSet); TargetObject->PostEditChangeProperty(PropertyChangedEvent); } }
UMaterial* T3DMaterialParser::ImportMaterial() { FString ClassName, Name, Value; UClass * Class; ensure(NextLine()); ensure(IsBeginObject(ClassName)); ensure(ClassName == TEXT("Material")); ensure(GetOneValueAfter(TEXT(" Name="), Name)); FString BasePackageName = FString::Printf(TEXT("/Game/UDK/%s/Materials"), *Package); FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools"); UMaterialFactoryNew* MaterialFactory = ConstructObject<UMaterialFactoryNew>(UMaterialFactoryNew::StaticClass()); Material = (UMaterial*)AssetToolsModule.Get().CreateAsset(Name, BasePackageName, UMaterial::StaticClass(), MaterialFactory); if (Material == NULL) { return NULL; } Material->Modify(); while (NextLine() && !IsEndObject()) { if (IsBeginObject(ClassName)) { if (ClassName == TEXT("MaterialExpressionFlipBookSample")) { Class = UMaterialExpressionTextureSample::StaticClass(); } else { Class = (UClass*)StaticFindObject(UClass::StaticClass(), ANY_PACKAGE, *ClassName, true); } if (Class) { ensure(GetOneValueAfter(TEXT(" Name="), Name)); FRequirement TextureRequirement; UMaterialExpression* MaterialExpression = ImportMaterialExpression(Class, TextureRequirement); UMaterialExpressionComment * MaterialExpressionComment = Cast<UMaterialExpressionComment>(MaterialExpression); if (MaterialExpressionComment) { Material->EditorComments.Add(MaterialExpressionComment); MaterialExpressionComment->MaterialExpressionEditorX -= MaterialExpressionComment->SizeX; FixRequirement(FString::Printf(TEXT("%s'%s'"), *ClassName, *Name), MaterialExpression); } else if (MaterialExpression) { Material->Expressions.Add(MaterialExpression); FixRequirement(FString::Printf(TEXT("%s'%s'"), *ClassName, *Name), MaterialExpression); } if (ClassName == TEXT("MaterialExpressionFlipBookSample")) { ImportMaterialExpressionFlipBookSample((UMaterialExpressionTextureSample *)MaterialExpression, TextureRequirement); } } else { JumpToEnd(); } } else if (GetProperty(TEXT("DiffuseColor="), Value)) { ImportExpression(&Material->BaseColor); } else if (GetProperty(TEXT("SpecularColor="), Value)) { ImportExpression(&Material->Specular); } else if (GetProperty(TEXT("SpecularPower="), Value)) { // TODO } else if (GetProperty(TEXT("Normal="), Value)) { ImportExpression(&Material->Normal); } else if (GetProperty(TEXT("EmissiveColor="), Value)) { ImportExpression(&Material->EmissiveColor); } else if (GetProperty(TEXT("Opacity="), Value)) { ImportExpression(&Material->Opacity); } else if (GetProperty(TEXT("OpacityMask="), Value)) { ImportExpression(&Material->OpacityMask); } else if (IsProperty(Name, Value)) { UProperty* Property = FindField<UProperty>(UMaterial::StaticClass(), *Name); if (Property) { Property->ImportText(*Value, Property->ContainerPtrToValuePtr<uint8>(Material), 0, Material); } } } PrintMissingRequirements(); return Material; }
UMaterialExpression* T3DMaterialParser::ImportMaterialExpression(UClass * Class, FRequirement &TextureRequirement) { if (!Class->IsChildOf(UMaterialExpression::StaticClass())) return NULL; UMaterialExpression* MaterialExpression = ConstructObject<UMaterialExpression>(Class, Material); FString Value, Name, PropertyName, Type, PackageName; while (NextLine() && IgnoreSubs() && !IsEndObject()) { if (GetProperty(TEXT("Texture="), Value)) { if (ParseRessourceUrl(Value, TextureRequirement)) { LevelParser->AddRequirement(TextureRequirement, UObjectDelegate::CreateRaw(LevelParser, &T3DLevelParser::SetTexture, (UMaterialExpressionTextureBase*)MaterialExpression)); } else { UE_LOG(UDKImportPluginLog, Warning, TEXT("Unable to parse ressource url : %s"), *Value); } } else if (IsProperty(PropertyName, Value) && PropertyName != TEXT("Material") && PropertyName != TEXT("ExpressionGUID") && PropertyName != TEXT("ObjectArchetype")) { if (Class->GetName() == TEXT("MaterialExpressionDesaturation") && PropertyName == TEXT("Percent")) { PropertyName = TEXT("Fraction"); } else if (Class == UMaterialExpressionConstant4Vector::StaticClass()) { if (PropertyName == TEXT("A")) ((UMaterialExpressionConstant4Vector*)MaterialExpression)->Constant.A = FCString::Atof(*Value); else if (PropertyName == TEXT("B")) ((UMaterialExpressionConstant4Vector*)MaterialExpression)->Constant.B = FCString::Atof(*Value); else if (PropertyName == TEXT("G")) ((UMaterialExpressionConstant4Vector*)MaterialExpression)->Constant.G = FCString::Atof(*Value); else if (PropertyName == TEXT("R")) ((UMaterialExpressionConstant4Vector*)MaterialExpression)->Constant.R = FCString::Atof(*Value); } else if (Class == UMaterialExpressionConstant3Vector::StaticClass()) { if (PropertyName == TEXT("B")) ((UMaterialExpressionConstant3Vector*)MaterialExpression)->Constant.B = FCString::Atof(*Value); else if (PropertyName == TEXT("G")) ((UMaterialExpressionConstant3Vector*)MaterialExpression)->Constant.G = FCString::Atof(*Value); else if (PropertyName == TEXT("R")) ((UMaterialExpressionConstant3Vector*)MaterialExpression)->Constant.R = FCString::Atof(*Value); } UProperty* Property = FindField<UProperty>(Class, *PropertyName); UStructProperty * StructProperty = Cast<UStructProperty>(Property); if (StructProperty && StructProperty->Struct->GetName() == TEXT("ExpressionInput")) { FExpressionInput * ExpressionInput = Property->ContainerPtrToValuePtr<FExpressionInput>(MaterialExpression); ImportExpression(ExpressionInput); } else if (Property) { Property->ImportText(*Value, Property->ContainerPtrToValuePtr<uint8>(MaterialExpression), 0, MaterialExpression); } } } MaterialExpression->Material = Material; MaterialExpression->MaterialExpressionEditorX = -MaterialExpression->MaterialExpressionEditorX; return MaterialExpression; }
void USpeedTreeImportData::LoadOptions() { int32 PortFlags = 0; for (UProperty* Property = GetClass()->PropertyLink; Property; Property = Property->PropertyLinkNext) { if (!Property->HasAnyPropertyFlags(CPF_Config)) { continue; } FString Section = TEXT("SpeedTree_Import_UI_Option_") + GetClass()->GetName(); FString Key = Property->GetName(); const bool bIsPropertyInherited = Property->GetOwnerClass() != GetClass(); UObject* SuperClassDefaultObject = GetClass()->GetSuperClass()->GetDefaultObject(); const FString& PropFileName = GEditorPerProjectIni; UArrayProperty* Array = dynamic_cast<UArrayProperty*>(Property); if (Array) { FConfigSection* Sec = GConfig->GetSectionPrivate(*Section, 0, 1, *GEditorPerProjectIni); if (Sec != nullptr) { TArray<FConfigValue> List; const FName KeyName(*Key, FNAME_Find); Sec->MultiFind(KeyName, List); FScriptArrayHelper_InContainer ArrayHelper(Array, this); // Only override default properties if there is something to override them with. if (List.Num() > 0) { ArrayHelper.EmptyAndAddValues(List.Num()); for (int32 i = List.Num() - 1, c = 0; i >= 0; i--, c++) { Array->Inner->ImportText(*List[i].GetValue(), ArrayHelper.GetRawPtr(c), PortFlags, this); } } else { int32 Index = 0; const FConfigValue* ElementValue = nullptr; do { // Add array index number to end of key FString IndexedKey = FString::Printf(TEXT("%s[%i]"), *Key, Index); // Try to find value of key const FName IndexedName(*IndexedKey, FNAME_Find); if (IndexedName == NAME_None) { break; } ElementValue = Sec->Find(IndexedName); // If found, import the element if (ElementValue != nullptr) { // expand the array if necessary so that Index is a valid element ArrayHelper.ExpandForIndex(Index); Array->Inner->ImportText(*ElementValue->GetValue(), ArrayHelper.GetRawPtr(Index), PortFlags, this); } Index++; } while (ElementValue || Index < ArrayHelper.Num()); } } } else { for (int32 i = 0; i < Property->ArrayDim; i++) { if (Property->ArrayDim != 1) { Key = FString::Printf(TEXT("%s[%i]"), *Property->GetName(), i); } FString Value; bool bFoundValue = GConfig->GetString(*Section, *Key, Value, *GEditorPerProjectIni); if (bFoundValue) { if (Property->ImportText(*Value, Property->ContainerPtrToValuePtr<uint8>(this, i), PortFlags, this) == NULL) { // this should be an error as the properties from the .ini / .int file are not correctly being read in and probably are affecting things in subtle ways UE_LOG(LogSpeedTreeImportData, Error, TEXT("SpeedTree Options LoadOptions (%s): failed for %s in: %s"), *GetPathName(), *Property->GetName(), *Value); } } } } } }