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 trialRick Hoekman
9,494 PointsMaterial 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);
}
}
3 Answers
Alexander Davison
65,469 PointsYou said "Maintex", try changing that to "MainTex" (computers are super picky even about uppercase and lowercase letters!)
Hope this helps! ~Alex
Rick Hoekman
9,494 PointsOh djeez.. haha typical (Should have seen that) Thanks for your time and help buddy! :D
Alexander Davison
65,469 PointsNo problem
Rick Hoekman
9,494 PointsAlexander Davison : Thanks for your response and helping me out :) Video is linked below:
https://teamtreehouse.com/library/materials-in-unity/scripting-materials/animating-material-offsets
Alexander Davison
65,469 PointsThanks! I'll try to find the error soon (it'll take some time)
Rick Hoekman
9,494 PointsNo 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!
Alexander Davison
65,469 PointsAlexander Davison
65,469 Pointscan you show a link to the video/code challenge? Thanks! That'll help a lot.