How do I alter the Emissive colour of a material using C# script at the Start() of runtime?
I've had a trawl through the internet and found countless different ways to do this, but none of them are working for me.
I'm working in the HDRP and I'm making a neon sign. The Game Object itself has been simplified down to a box until I get this working and then I'll take it on over to the correct Objects.
I've attached an image with what variables I'm trying to change.
Here is a short snippet of my code.
[SerializeField] private Material primaryColorEmissions;
void Start() {
primaryColorEmissions.SetColor("_EmissiveColor", brand.primaryColor);
primaryColorEmissions.SetInt("_EmissiveIntensity", 100);
primaryColorEmissions.EnableKeyword("_EMISSION");
}
brand is a scriptable object of type Brand and contains 'public Color primaryColor;' variable used in the above. I've set the emissive intensity to an arbitrary number until this is working.
According to the shader I'm using these should be the correct variable names for emissive properties.
[HDR] _EmissiveColor("EmissiveColor", Color) = (0, 0, 0)
// Used only to serialize the LDR and HDR emissive color in the material UI,
// in the shader only the _EmissiveColor should be used
[HideInInspector] _EmissiveColorLDR("EmissiveColor LDR", Color) = (0, 0, 0)
_EmissiveColorMap("EmissiveColorMap", 2D) = "white" {}
[ToggleUI] _AlbedoAffectEmissive("Albedo Affect Emissive", Float) = 0.0
[HideInInspector] _EmissiveIntensityUnit("Emissive Mode", Int) = 0
[ToggleUI] _UseEmissiveIntensity("Use Emissive Intensity", Int) = 0
_EmissiveIntensity("Emissive Intensity", Float) = 1
_EmissiveExposureWeight("Emissive Pre Exposure", Range(0.0, 1.0)) = 1.0
Could somebody please help me figure out where I'm going wrong with this because It's driving me insane.