- Home /
www.texture results in black texture in Android
Using WWW I have loaded image from Android Mobile to www object
planeObj.renderer.material.mainTexture = www.texture;
I am sure image is loaded because www.bytesDownloaded prints exact number of bytes in the image.
Debug.Log ("No of bytes downloaded are " + www.bytesDownloaded);
Here is my full code attached to an empty game object. this shows actual image when I play in Unity, but when the android app is running, I m getting a black image.
public class ExampleClass : MonoBehaviour {
GameObject Cube;
public string url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";
IEnumerator Start() {
GameObject planeObj = GameObject.CreatePrimitive (PrimitiveType.Cube);
planeObj.name="SuperPlane";
planeObj.transform.eulerAngles = new Vector3 (270,180f, 0f);
planeObj.transform.localScale = new Vector3 (1.0f, 0, 1.0f);
WWW www = new WWW(url);
yield return www;
planeObj.renderer.material.mainTexture = www.texture;
}}
If it is not able to access image it should show ? image, I am getting image as black in color and there is no error in the android logcat console. I have also added a light to make it visible.
edit : simplfied the question to minute level.
Normally I'd reject this kind of question. Your code is hosted on an external server, which might download viruses, or interfere with the browser. (I know with paste bin this is unlikely). Also, you are relying on users to go and look at your code, when you could just paste it inline in your question. Also, you show us how you assign the texture to the material. Does that assignment work? Can you display the texture in a GUITexture? What errors, if any, get written to logcat?
thanks a lot for encouraging newbie, I have simplified question to my best and modified as per your comments
Answer by madhu131313 · Apr 03, 2015 at 12:21 PM
I don't how this is working, if someone explains that will be great.
In Android player settings, I have changed Rendering path to Vertex lit instead of "Forward" It is also not working for other option "Deferred Lighting"
This is not an answer. by accepting this you discourage others from giving better answers
Answer by trololo · Apr 02, 2015 at 08:25 AM
Try the following:
WWW www = new WWW(url);
yield return www;
if(www != null && www.error == null)
{
Texture2D text = new Texture2D(128, 128, TextureFormat.DXT1, false); //TextureFormat must be DXT
texture.renderer.material.mainTexture = text;
www.LoadImageIntoTexture(text);
}
my method and your method are working when I load url from web or local image in unity play, but it is displaying black texture in Android in all the cases. $$anonymous$$y game object is dynamically created. When I use a gameobject in scene, I am able to see proper image. Can you please run my code mentioned in your mobile.
This is not working, my game runs fine on android 4.2 but has this problem with 4.4