Color tool works but not ent:SetColor() on prop_effect

Hi,

By default prop_effects spawned with ents.Create have a “melon” model where the green ring is. This is because the default model of prop_effect is actually a melon, and the hev suit (or whatever you see) is actually it’s .attachedentity

Anwyays, I am trying to color the melon to make it invisible. With the toolgun, this works fine! But if I try using ent:Color and Color( 0, 0, 0, 0 ) it does not work. I’ve tried setting the render group and render mode sort of like how the toolgun does.

Any advice would be appreciated.

Thank you!

I managed to hide the watermelon on my side using this:

local ent = Entity(1):GetEyeTrace().Entity
ent:SetColor( Color( 0, 0, 0, 0 ) )
ent:SetRenderMode( RENDERMODE_TRANSCOLOR )

It seems when the alpha component of the color is edited, the toolgun applies a hack to change the render mode of the entity: garrysmod/colour.lua at 4aefc7d7f468998cd3239c0baa560a389f27d884 · Facepunch/garrysmod · GitHub

I hope this helps you achieve what you want. Otherwise, please send a demo code here so other people can help you.

I tried running your code while looking directly at the melon and it didn’t go away for me.
Specifically, I enabled sv_cheats 1 and used the console command

lua_run local ent = Entity(1):GetEyeTrace().Entity ent:SetColor( Color( 0, 0, 0, 0 ) ) ent:SetRenderMode( RENDERMODE_TRANSCOLOR )

Can you give me a sample code?

Literally just running that exact code of yours in console. And I know it works because I tested it on a blue barrel and it successfully disappeared.

Let me ask, how are you creating the melon prop under the effect?
What I am doing is creating a “static entity” script where ents I choose get added to a table, saved as JSON in a file, then loaded back when the game restarts. Every time after this restart, when loaded back in, the melons are present.
And that’s when I try, unsuccessfully, to make them invisibois.

Thank you for the help so far. Hope we can get this fixed!

Here is the code where the static’d (props, ents, effects, whatever) are loaded in

function MYGM.Shared.LoadStaticProps()

	if SERVER then
		if file.Exists( "mygm/"..gmFolderName.."/"..game.GetMap()..".json", "DATA" ) then

			local MYGMStaticPropsJSONStringFromFile = file.Read( "mygm/"..gmFolderName.."/"..game.GetMap()..".json", "DATA" )
			MYGM.Shared.CurrentStaticPropsTable = util.JSONToTable( MYGMStaticPropsJSONStringFromFile )
			
			for k, v in pairs( MYGM.Shared.CurrentStaticPropsTable ) do
			
				local prop = ents.Create( v.class )
				
				
				if v.model then prop:SetModel( v.model ) end
				--v.bodygroups -- This is trickier end
				if v.skin then prop:SetSkin( v.skin ) end
				if v.color then prop:SetColor( v.color ) end
				if v.material then prop:SetMaterial( v.material ) end
				if v.pos then prop:SetPos( v.pos ) end
				if v.prop then prop:SetAngles( v.angles ) end
				
				if v.attachedmodel then 
				
					prop.AttachedEntity = ents.Create( "prop_dynamic" )
					prop.AttachedEntity:SetModel( v.attachedmodel )
					prop.AttachedEntity:SetAngles( v.angles )
					prop.AttachedEntity:SetPos( v.pos )
					prop.AttachedEntity:SetSkin( v.skin )
					prop.AttachedEntity:Spawn()
					prop.AttachedEntity:SetParent( prop )
					prop.AttachedEntity:DrawShadow( false )
				
					-- Hide the melon :)
					
					prop:SetColor( Color( 0, 0, 0, 0 ) )
					prop:SetRenderMode( RENDERMODE_TRANSCOLOR )
				
				end
				
				
				-- also need to handle submaterials, im not even saving them correctly
				
				prop:Spawn()
				
				if (v.frozen == true) then
					prop:GetPhysicsObject():EnableMotion( false )
				end
				
				-- After everything is done, let's tell the entity its index in the table
				prop.IsMygmStaticProp = true
				local PropTable = MYGM.Shared.GetPropDataTable( prop )
				prop.MygmStaticPropIndex = table.KeyFromValue( MYGM.Shared.CurrentStaticPropsTable, PropTable )
				
			end
			

		else -- If no file exists, we create the staticpropstable for the first time here
			MYGM.Shared.CurrentStaticPropsTable = {}
		end
	end
end

Have you tried applying this to the prop.AttachedModel variable?

Something strange happens.

When I do it through console, looking directly at the Melon, on .AttachedEntity like you suggest(?) the melon disappears.

However, when I do it through code with prop.AttachedEntity, it just makes the prop (eg: hev suit) invisible and the melon stays.

Honestly, I couldn’t give you an answer, maybe there is a necessary delay between the spawn of your entity and the possibility to apply invisibility on it. Try to ask on the Garry’s Mod Discord, maybe some people have experienced the same issue like you but without the full code I couldn’t help you more.

Yeah, I was thinking maybe it could be the fact that I re-assign .AttachedEntity when I create the prop_dynamic, but even attempting to make it invisible sooner didn’t work. I might check out the gmod discord. I am starting to wonder if there is just some sort of auto-utility in Gmod itself that goes around placing these melons.

But I have seen static effects done successfully before.

Hmm so I think I got it working.

I switched things around.

Now, AttachedEntity is simply a created melon, and “prop” is what gets set to the actual model.

-- v.attachedmodelang is simply the angle of the original, hand-spawned prop_effect, stored when we save it
			if v.attachedmodel then 
					
				
					prop.AttachedEntity = ents.Create( "prop_dynamic" )
					prop.AttachedEntity:SetModel( "models/props_junk/watermelon01.mdl" )
					prop.AttachedEntity:SetAngles( v.attachedmodelang )
					prop.AttachedEntity:SetPos( v.pos )
					prop.AttachedEntity:SetSkin( v.skin )
					prop.AttachedEntity:Spawn()
					prop.AttachedEntity:SetParent( prop )
					prop.AttachedEntity:DrawShadow( false )
				
					-- Hide the melon :)
					prop.AttachedEntity:SetColor( Color( 0, 0, 0, 0 ) )
					prop.AttachedEntity:SetRenderMode( RENDERMODE_TRANSCOLOR )
					
					prop:SetModel( v.attachedmodel )
					prop:SetPos( prop.AttachedEntity:GetPos() )
					prop:SetAngles( v.attachedmodelang )
				
				end

That seems to have it working.
TYSM for all the help. :slight_smile:

1 Like