Move Terrain.WaterColor to Terrain.MaterialColors

As a Roblox Developer, it is currently too hard to read water terrain’s material color from a raycast without making a special if case for when the material is water.

print(workspace.Terrain:GetMaterialColor(Enum.Material.Water))
22:44:44.848 - Unsupported terrain material

If Roblox is able to address your issue, how would it improve your game and/or your development experience? Please be as specific as possible.

Deprecate Terrain.WaterColor and move it under MaterialColors and it’s respective APIs. (Get/SetMaterialColor())

What about the other water oriented properties in the Terrrain class?

WaterColor used to be specific to water. Now that it has been expanded to other terrain materials, it has to be moved in with them. As for the other properties, they are still specific to water. They’ll be fine for now.

4 Likes

How come you’re using GetMaterialColor() instead of reading the WaterColor property itself when your code detects Water? I do agree that the setup is a bit messy but frankly Water is the easiest Terrain property to read.

if material == Enum.Material.Water then print(workspace.Terrain.WaterColor)
else print(workspace.Terrain:GetMaterialColor(material)) end
1 Like

I was writing a raycasting minimap generator (because everyone wants one these days) and first only programmed it to supply colors based on GetMaterialColor. This is what the code looks like now because of this lol.

local function cast(pos,depth)
	local ray = Ray.new(pos,Vector3.new(0,-depth,0))
	local contact,intersect,surface,material = workspace:FindPartOnRay(ray)
	lol.CFrame = CFrame.new(intersect)
	if contact.ClassName == 'Terrain' then -- Terrain logic huehuehue
		if material == Enum.Material.Water then -- God damn it this API
			return workspace.Terrain.WaterColor
		end
		return workspace.Terrain:GetMaterialColor(material)
	end
	
	return contact.Color
end

lol is a debug part btw