Hello! I'm puzzled by the SetMaterial() behavior.
I have a scene with randomly disposed cubes made in the editor. When I do the mouse pick on a cube, I check its material, and switch/toggle the material of the cube. I have two separate materials, one with and the other without the emission texture/shader. Now, when I pick the closest cube and toggle its material, some of the other cubes (but not all) get the same material. Sometimes only one cube switches material, sometimes two or more. Everytime the same group of cubes react to the single cube picking/material setting, so apparently that's not something random.
For the sake of completeness, I have tried to make individual cubes both with brushes and CTRL-axis drag & drop. The result is similar.
Now, I suppose that this behavior has something to do with the Entity:Instance() VS Entity:Copy(). But could be totally wrong
N.B. I use the closest entity option in the Pick routine.
Here is my pick routine:
local window = Window:GetCurrent()
local context = Context:GetCurrent()
if (window:MouseHit(1)) then
local pickinfo = PickInfo()
if (self.camera:Pick(context:GetWidth() / 2, context:GetHeight() / 2,pickinfo,0,true)) then
if (pickinfo.entity:GetMaterial() == self.blokMatNormal) then
pickinfo.entity:SetMaterial(self.blokMatEmissive)
else
pickinfo.entity:SetMaterial(self.blokMatNormal)
end
end
end