Set Material Parameter Bug

Summary

After the latest patch, it doesn’t work anymore

set Material.Texture = Texture
Prop.SetMaterial(Material)

Please select what you are reporting on:

Unreal Editor for Fortnite

What Type of Bug are you experiencing?

Verse

Steps to Reproduce

Any attempt to change Texture parameter in material with code

Expected Result

New texture is applied as parameter

Observed Result

Nothing is changed

Platform(s)

Windows, other platforms not tested

Island Code

Any island

Thank you, we’re checking into this.

Thank you! let me know if you will need additional info on this

1 Like

Will do, thank you!

I also had this issue in my code. What i found was that any material that I initialized directly as a class variable (i.e.)…

var my_material : custom_material_instance = custom_material_instance{}

…wouldn’t work. I ended up reinitializing them in a class method and they began working. IE:

InitMaterials():
      set my_material = custom_material_instance{}
      set my_material.parameter = whatever

See if this works around the bug.

This is also the same issue:

1 Like

Do you have any more information on how to reproduce the issue you are experiencing? In it’s simplest case we are seeing the material update on the prop, so in this code the prop does get the new material applied

material_device := class(creative_device):
    
    var Material : MyMaterial_material = MyMaterial_material{}

    @editable
    Prop : creative_prop = creative_prop{}

    OnBegin<override>()<suspends>:void=
        Prop.SetMaterial(Material)

However we have noticed a problem setting a parameter while initializing the class variable

material_device := class(creative_device):
    
    var Material : MyMaterial_material = MyMaterial_material{ ColorParam := NamedColors.Red }

    @editable
    Prop : creative_prop = creative_prop{}

    OnBegin<override>()<suspends>:void=
        Prop.SetMaterial(Material)

In this example the red color does not get applied, even though the material itself is. Is this the problem you are hitting?

We investigated the other thread mentioned here and found that to be an issue specific to arrays. Are you using arrays of materials in your code?

FORT-830305 changed to ‘Needs More Info’. We’re missing information that would help us determine the source of the issue.

This code stopped working the day that Chapter 6 update went live. No texture was assigned to the prop when InitMaterial() was called (it remained the default world grid texture):

TokenWrapper<public> := class<unique>():
    var Token : ?creative_prop = false
    var Type : int = 0
    var my_material : MI_TokenSprite_Atlas_material = MI_TokenSprite_Atlas_material{}

    SetMaterialValue() : void =
        set my_material.TokenValue = (Type * 1.0)

    InitMaterial<public>() : void =
        if:
            prop := Token?
        then:
            prop.SetMaterial(my_material)

After changing to this, it started working again:

TokenWrapper<public> := class<unique>():
    var Token : ?creative_prop = false
    var Type : int = 0
    var maybe_my_material : ?MI_TokenSprite_Atlas_material= false

    SetMaterialValue() : void =
        if(my_material := maybe_my_material?):
            set my_material.TokenValue = (Type * 1.0)

    InitMaterial<public>() : void =
        if:
            not maybe_my_material?
        then:
            set maybe_my_material = option{MI_TokenSprite_Atlas_material{}}
        if:
            prop := Token?
            my_material := maybe_my_material?
        then:
            prop.SetMaterial(my_material)

MI_TokenSprite_Atlas_material is a material instance that does have a float parameter.

1 Like

I’ve encountered randomly a bug where materials even on non-arrays were not being instanced correctly, but instancing them on game start worked just fine. I assumed this is probably similar to what the creator of this thread was experiencing. I don’t know what could trigger the material to not instance but I have definitely had it happen on non-arrayed materials.

I have made a device that toggles between using the instanced material or instancing a new one and then changing the variable to that.

I have also packed the Project Files from the project shown in the video .
ProjectFiles.zip (141.0 KB)s

1 Like

Thanks both for the repro, once again was very helpful in identifying the issue.

This appears to be a bug coming from the material being a default subobject of an arbitrary class (as opposed to a creative_device or scene graph component).

It’s actually a relatively complex problem to solve systemically which we will have to try to address over the coming releases. But like people here have identified, it’s definitely a suitable workaround just to dynamically instantiate the materials rather than relying on member vars initialised with the class.

In your example @Mineblo it should also work if you made the pinpad_device a default subobject of your creative device. So this code should work fine

game_manager:=class(creative_device):

    MyClass:pinpad_device = pinpad_device{}

    OnBegin<override>()<suspends> : void =    
        MyClass.InitClass()


pinpad_device := class<unique>():
    
    var DoorMaterial : Material.Mato_material = Material.Mato_material{}

    InitClass():void=
        Result:=SpawnProp(DefaultCreativePropAsset,transform{})
        if(MyProp:=Result(0)?):
            MyProp.SetMaterial(DoorMaterial)
1 Like