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
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.
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
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