Changing the skybox texture before it's drawn

Hello. I found this on the wiki


function GM:PreDrawSkyBox()    return true
end

And it seems to do the job. But how can I change it to a different texture AFTER that has been called? I’m not even sure if this is possible, but it’s worth a try I guess.



if CLIENT then
//This is the fun stuff!

local NewBoxName = "sky_day02_09"
local OldBox = nil
local Box = false
local SkyBoxMaterials = {}
local SkyBoxSuffixes = {"up", "dn", "lf", "rt", "bk", "ft"}
 
// This funciton gets the current skybox materials and saves them
local function GetSkyboxMats()
    OldBox = GetConVarString("sv_skyname")
	
    for _, Suffix in ipairs(SkyBoxSuffixes) do 
        SkyBoxMaterials[Suffix] = Material("skybox/"..OldBox..Suffix)  
    end
	
end

//replace the current skybox mat with the given one
local function SetSkyBox(name)
    for Suffix, SkyMat in pairs(SkyBoxMaterials) do
        SkyMat:SetMaterialTexture("$basetexture", Material("skybox/"..name..Suffix ):GetMaterialTexture("$basetexture"))
    end
end

concommand.Add("snow_skyboxswap", function()//the fucntion that determines what to swap for what
	Box = not Box
	if (Box) then
		SetSkyBox(NewBoxName)
		
	else
		SetSkyBox(OldBox)
	end
end)

//hooks
hook.Add("InitPostEntity", "SkyBox.InitPostEntity", GetSkyboxMats)
end


This will swap between two skyboxes on demand. Note: if you reload the script, the skybox get’s stuck at whatever it is atm, so you have to actually rejoin.

Thanks. That didn’t work for what I needed it for but pretty cool :stuck_out_tongue:

Anyways, another question is it possible to remove say a sky_camera with lua at a specific location? or just with the entity name?

Ya, you could loop through all the entities and search for sky_camera, or if you know the position of the sky camera, you could loop through all the entities and check if they are at that position, and if so, remove them…

There’s probably a better way, but anyways :stuck_out_tongue:


for k,v in pairs(ents.GetAll()) do
if v:GetClass() == "sky_camera" then
v:Remove()
end

// OR

if v:GetPos() == Vector(X,Y,Z) then
v:Remove()
end
end

Just a thought :stuck_out_tongue:


ents.FindByClass("sky_camera")[1]

:v:

Ah, thought it was something like that, couldn’t quite remember exactly though :stuck_out_tongue:

I only can change the skybox material once. Is it normal ?

I really need an answer.

Why the fuck did you bump this?