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

Rick Hoekman
Rick Hoekman
9,494 Points

Material doesn't have a texture property '_Maintex'

I'm getting this error in the console:

Material doesn't have a texture property '_Maintex' UnityEngine.Material:SetTextureOffset(String, Vector2) AnimatedMaterial:Update() (at Assets/AnimatedMaterial.cs:36)

Below the content of AnimatedMaterial.cs :

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.02f;


    // Use this for initialization
    void Start () {

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


        // Get this intial immision color
        startEmissionColor = mat.GetColor ("_EmissionColor");

        mat.SetColor ("_EmissionColor", startEmissionColor);

    }

    // 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 * glow);
        DynamicGI.UpdateMaterials (rend);

    }
}

can you show a link to the video/code challenge? Thanks! That'll help a lot.

3 Answers

You said "Maintex", try changing that to "MainTex" (computers are super picky even about uppercase and lowercase letters!) :smile:

Hope this helps! ~Alex

Rick Hoekman
Rick Hoekman
9,494 Points

Oh djeez.. haha typical (Should have seen that) Thanks for your time and help buddy! :D

No problem :smile:

Thanks! I'll try to find the error soon (it'll take some time)

Rick Hoekman
Rick Hoekman
9,494 Points

No rush :) I'm able to move forward in the course despite this error.. Just like to know what it is to fix it.. debugging is all part of being an aspiring developer :D Thanks for taking the time!