Jump to content

Script color property returns unexpected results

Recommended Posts

Playing around with a script that allows the user to pick a color from the object panel to be used with a shader. Setting the initial value of the color works as expected and fills out the property panel correctly:

Script.MyColor = Vec4(1,0,0,1)--Color "MyColor"



But if the color property is modified via the panel, then it will return a number based on the 0-255 scale which will fail in the shader.


In an attempt to work around this, I changed my initial value to:

Script.MyColor = Vec4(255,0,0,255)--Color "MyColor"

which results in this:


which gives weird property panel results and still would be unuseable in my shader without dividing each component by 255.


Since I have no viable method to determine if the color is being set by default or by the color picker, the returned color needs to be on a 0-1 scale to work properly.


example script:

Script.MyColor = Vec4(1,0,0,1)--Color "MyColor"

function Script:Start()
  local color = self.MyColor
  System:Print(color.r..", "..color.g..", "..color.b..", "..color.a)

Share this post

Link to post

Just pointing out that all the LE color features (SetColor, shaders, and even setting the color picker property) use the 0-1 scale except for the color picker's returned values. For consistency and to avoid problems as pointed out above, the color picker should return values scaled 0-1 instead of 0-255.

Share this post

Link to post

Fixed for the next build. The editor will show colors as 0-255 but the engine will divide by 255 on loading.

Share this post

Link to post
This topic is now closed to further replies.
  • Create New...