Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Game Development Materials in Unity Scripting Materials Animating Emissive Colors

collin banhagel
collin banhagel
3,677 Points

CS0619 'DynamicGI.UpdateMaterials(Renderer)' is obsolete

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class AnimatedMaterial : MonoBehaviour {

private Renderer rend;
private Material mat;
private Color startEmissionColor;

[SerializeField]
private float offsetSpeed = 0.02f;

[SerializeField]
private float glowSpeed = 0.2f;

// Use this for initialization
void Start() {

    // Get the renderer and the material
    rend = GetComponent<Renderer>();
    mat = rend.material;

    // Get the intial emission color
    startEmissionColor = mat.GetColor("_EmissionColor");
}

// Update is called once per frame
void Update () {

    float offset = Time.time * offsetSpeed;
    mat.SetTextureOffset("_MainTex", new Vector2(0, offset));

    float glow = Mathf.PingPong(Time.time * glowSpeed, 1f);
    mat.SetColor ("_EmissionColor", startEmissionColor);

    DynamicGI.UpdateMaterials(rend);

}

}

Hi Collin,

In the recent version they made Dynamic.GI.UpdateMaterials obsolete. I will post the new method, but I highly recommend you let Unity throw the error, and see if you can figure out the new solution from what it says.

At the end of the Update() function:

// Use our "Renderer" to call its own "UpdateGIMaterials()" method

rend.UpdateGIMaterials();

Basically, they changed the way updates to Global Illumination are performed in this more recent version of Unity. Now it's a method attached to each Renderer component (which we stored in "rend" in our code) instead of the Dynamic.GI class. This is super cool, actually, as it makes coding it a cinch and the code is now portable; you could apply this script to any Renderer as a component and it will correctly update its own GI materials without further changes needed to the code.