- Home /
Load texture on disabled GameObject
I'm using the following script to download textures from a URL and apply them to GameObjects, the script is on each GameObject that requires a texture:
public class LoadTex : MonoBehaviour {
public string url;
IEnumerator Start()
{
WWW www = new WWW(url);
yield return (www);
Renderer renderer = GetComponent<Renderer> ();
renderer.material.mainTexture = www.texture;
}
}
This works great on GameObjects that are active on start up but when I turn on a GameObject during runtime, it shows no texture.
Why is this and how do I fix the issue?
Answer by tormentoarmagedoom · Sep 13, 2017 at 02:17 PM
Good day @hollym16 !
Making a GameObject inactive will disable every component, turning off any attached renderers, colliders, rigidbodies, scripts, etc... Any scripts that you have attached to the GameObject will no longer have Update()
If a GameObject is
SetActive(false)
All its components remain inactive, so you can not modify any porperty, laod textures... nothing.
You only need to
SetActive(true);
do all you want, and again
SetActive(false)
Upvote & ask for more info using @tormentoarmagedoom
Bye:D
Your answer
Follow this Question
Related Questions
Assigning a texture to a renderer 0 Answers
How to assign texture from url 1 Answer
Best way to determine WWW timeout/404/etc.? 2 Answers