How to access Emission Color of a Material in Script?

Hi, so I need a way to change the color of an Object over texture. So I guess the emission light color should be what I want. But I simply call it in Unity by using Material.SetColor(“_Emission”, newColor) as described in UnityDoc:

But it seems not working. Am I right to use dat function?
BTW, it could be changed in Inspector.

I changed the emission color with this code:

Material mymat = GetComponent<Renderer>().material;
        mymat.SetColor("_EmissionColor", Color.red);

@millanow, You need to call the following before setting the _EmissionColor.

gameObject.GetComponent).material.EnableKeyword(“_EMISSION”);

I had the same issue and found this solution elsewhere.

You have to make sure that the Emission property on the material is enabled, which you can do using: material.EnableKeyword("_EMISSION");. You will also have to use DynamicGI.UpdateEnvironment(); if you want the emission lighting to affect the environment. Take a look at this article. It explains all the little details you have to take care of to get emission lighting to work properly: https://blog.terresquall.com/2020/01/getting-your-emission-maps-to-work-in-unity/

Calling Material.SetColor(“_Emission”, newColor) only has an effect if the shader which is used to render the object actually has a variable called _Emission defined in it. This is the case for Vertex Lit shaders, as the docs also describe. Are you using a vertex lit shader?

this is because the shader wasnt in the scene at the start containing a entry called emission!
if u apply and enable emission through script without having a copy with those features in the scene from start it fails!