- Home /
Why are my textures black at runtime?
Hello all!
I suspect this might be something to do with the shader set up but my script which works happily with other objects is rendering the below image completely black at run time. Displays fine in Scene mode, but at runtime it's completely black. It is a Standard shader because I have a script that accesses the Alpha channel of the Color.
I have seen a few questions that relate to this but they are quite old and haven't helped me solve anything.
As I mentioned ealier this works fine on other object which are Spheres, but this is a plane is that gives anything away??
Anyone know what is wrong,
Just to add extra confusion, I have another Plane, with the same script on it, same set up but that renders fine.
this is the script I am using. The code in flashFunction() works for the stop sign and works fine!
The code in the regular update function effects the blue ring and doesn't work!
public class trailFader : $$anonymous$$onoBehaviour
{
public $$anonymous$$aterial my$$anonymous$$aterial;
public float fadeValue;
public string objectType;
public GameObject child;
public bool fadeDir;
public bool flashIn;
public void Awake()
{
objectType = gameObject.tag;
my$$anonymous$$aterial = gameObject.GetComponent<Renderer>().material;
if (transform.childCount != 0)
{
child = transform.GetChild(0).gameObject;
my$$anonymous$$aterial = child.gameObject.GetComponent<Renderer>().material;
}
}
public void Update()
{
if (objectType == "Untagged")
{
var newColor = my$$anonymous$$aterial.color;
newColor.a -= fadeValue;
my$$anonymous$$aterial.color = newColor;
if (newColor.a < 0)
{
Destroy(gameObject);
}
}
if (flashIn)
{
flashFunction();
}
}
public void flashFunction()
{
if (fadeDir)
{
var newColor = my$$anonymous$$aterial.color;
newColor.a += fadeValue*3;
my$$anonymous$$aterial.color = newColor;
if (newColor.a > 1)
{
fadeDir = !fadeDir;
}
}
if (!fadeDir)
{
var newColor = my$$anonymous$$aterial.color;
newColor.a -= fadeValue/3;
my$$anonymous$$aterial.color = newColor;
if (newColor.a < 0)
{
newColor.a = 0;
my$$anonymous$$aterial.color = newColor;
fadeDir = !fadeDir;
flashIn = false;
}
}
}
public void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Player"))
{
if (objectType == gameObject.tag)
{
flashIn = true;
fadeDir = true;
}
}
}
}
Answer by MrSteve2 · Aug 07, 2020 at 09:58 AM
Ok 1 last thing and I will keep schtum! I had another script on it that effects the scale. (Its grows basically)
Having disabled that, it renders fine. So now I guess it's a new questions, why does effecting the scale of it, effect how it renders?
Answer by BobyStar · Dec 21, 2021 at 05:21 AM
I am not exactly sure why scale would effect the rendering. It could be a floating point issue with lighting small areas or rendering small meshes.
For anyone who encounters this issue try these checks:
Make sure you are not scaling the object with a
Vector2
and that all scale axis's are not0
.Double check the material and texture properties
If it's an imported model, change the
Scale Factor
in the import settings.
If all else fails, try using an Unlit Shader
.
Your answer
![](https://koobas.hobune.stream/wayback/20220613005113im_/https://answers.unity.com/themes/thub/images/avi.jpg)