Lua brush entity material not showing up

Hello and thanks for taking your time to read about my issue:
I’m making a gamemode and I wanted people to easily be able to create maps without worrying about Lua at all. I wanted to be able to create a brush entity in Hammer and detect it via lua to apply the corresponding logic. I got pretty far on my own but my materials (defined with Hammer’s texture tool) are not showing up.

I’ve created a simple entity setting ENT.Base to “base_brush” and ENT.Type to “brush”. I’ve also defined the entity as a @SolidClass in my fgd file. To check that everything works I’ve made it so that a message is shown when ENT:StartTouch(). Everything seems fine, but I can’t get the material defined in Hammer to show up.

Printing self:GetMaterials()[1] returns the correct material (maps/gmodmap/dev/dev_blendmeasure_wvt_patch) but even when I try to self:SetMaterial() I can’t get it to work.

I also get the following error: Requesting texture value from var “$dummyvar” which is not a texture value (material: NULL material)



ENT = {}

ENT.Base = "base_brush"
ENT.Type = "brush"
    
function ENT:Initialize( key, value )
    print(self:GetMaterials()[1])
    self:SetMaterial(self:GetMaterials()[1], true)
end

function ENT:KeyValue( key, value )

    if !self.keyvalues then
        self.keyvalues = {}
    end
    print(key, value)
    self.keyvalues[key] = value

end

if ENT.Type then
    scripted_ents.Register( _G.ENT, "start_line" )
end

function ENT:StartTouch( entity )
    if entity:IsPlayer() and entity:IsValid() then
        for _, v in pairs(player.GetAll()) do
            v:PrintMessage(HUD_PRINTTALK, entity:GetName().. " touched it OMG.")
        end
    end
end


ENT = nil

I swear that code is just for quick testing purposes, I’ll write it in a cleaner way once I figure out all the details :excited:

Thanks for the help

A bit late, but you should look in this: http://wiki.garrysmod.com/page/IMesh/Draw
Or this: http://wiki.garrysmod.com/page/Category:mesh

I don’t think their is an “Automated function” for this, you must draw it manualy

Are you suggesting that I should use the entity only to the purposes of getting the dimensions of the original brush and then drawing it myself?

Is there any possibility that this is just the script being unable to access the material path? I guess that the material would be located inside the .bsp file right?

Try this clientside

[lua]function ENT:Draw()
self:DrawModel()
end[/lua]

If you are lucky, maybe it will work just fine

Brush entities are serverside only iirc.

I’ve set up a brush entity before. I don’t recall exactly what I did, but I do recall needing to set the model, possibly from a keyvalue. If there’s a keyvalue that has a string value that looks like “*5” (but with any number), use that as the model.