Change texture in lua Crashes Lumberyard but works in script canvas

I have a problem where when I run a line of code, lumberyard crashes.

	function texture:OnTriggerAreaEntered(Entered)
local eId = self.Properties.Platform
local mat = Material.LoadByName("textures/simplediffuse/white");
MaterialOwnerRequestBus.Event.SetMaterial(eId, mat); end

But when I use the script canvas to do the same thing, for some reason it works

Is there anything I’m doing wrong? or something I’m missing?


I’ve seen that in script canvas you can get your file extension wrong and it will check for what your file should have been named and load it successfully, perhaps Lua isn’t as forgiving. I see in the Lua code there is no .mtl extension used. You might see what you are using in SC for an extension and if it’s missing too, check whether you are getting a warning in the console when your graph runs.

Are you trying to set the material of the trigger area or the entity entering the trigger? In the graph you posted it will always set hexagon’s material. Here is a graph that is located on the same entity as the trigger area. The top changes the trigger area the bottom changes the entity that enters.

I haven’t tried setting materials in my own graphs but I do have a working example of changing material properties of an entity, where if you only want to change once instance of the material it is necessary to clone it first (otherwise every entity that shares the material will have share the change). Here I change material properties when a tag is added (and then lost to activate a toggle)

You are correct, I want to change hexagon’s material if the trigger area is activated. I thank you for the SC setup. I was actually going to use this for multiple hexagons, and I apologize because I wasn’t really planning on using SC for I think doing it in Lua is more flexible also I will have to get back to this question because I currently am updating lumberyard so I can’t test it right now.


Hi there, I tried adding the .mtl but the problem persists lumberyard crashes, as for the SC it will still work after adding .mtl.

Here is a screenshot of the error that pops out upon trigger.


No, I haven’t cloned it and yes there is a material on the object (black) and was planning to turn it white on trigger. (Edit) Cloned and crashed.

Nah, there isn’t anything there

Here’s something tho, the code works in lumberyard no problems.


I have had crashes when working with materials. Cloning the material before changing it resolved those issues, are you cloning it in Lua first? Another question, is the material set on the entity when everything starts or is it empty and you are populating it for the first time during runtime?

@ImPerplexed When you save your Lua, does the asset processor throw any errors? Compile errors will only display there.