Announcement

Collapse
No announcement yet.

Change Parent Material of Existing MaterialInstance

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Change Parent Material of Existing MaterialInstance

    Hi,

    I try to change the parent Material of the Material Instances which are in a specific folder of my project. I would like to create a function that archieve this and run it from the editor.
    Any Idea ?

    Thank you !

    #2
    The solution:
    Code:
                UMaterial* BaseMat = LoadMaterialFromPath(MaterialPath);
                UMaterialInstance* MatIns = LoadMaterialInstanceFromPath(InstancePath);
                MatIns->Parent = BaseMat;
    With loading functions :

    Code:
     UFUNCTION(BlueprintCallable, Category = "save")
        static FORCEINLINE ObjClass* LoadObjFromPath(const FString& Path)
        {
            if (Path == "") return NULL;
    
            return Cast<ObjClass>(StaticLoadObject(ObjClass::StaticClass(), NULL, *Path));
        }
    
        UFUNCTION(BlueprintCallable, Category = "save")
        static FORCEINLINE UMaterial* LoadMaterialFromPath(const FString& Path)
        {
            if (Path == "") return NULL;
    
            return LoadObjFromPath<UMaterial>(Path);
        }
    
        UFUNCTION(BlueprintCallable, Category = "save")
        static FORCEINLINE UMaterialInstance* LoadMaterialInstanceFromPath(const FString& Path)
        {
            if (Path == "") return NULL;
    
            return LoadObjFromPath<UMaterialInstance>(Path);
        }

    Comment

    Working...
    X