Author Topic: UITexture.mainTexture causes problem on Android  (Read 2918 times)

Oinobareion

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
UITexture.mainTexture causes problem on Android
« on: August 08, 2013, 09:27:17 AM »
Hi,

I am dynamically creating a GameObject and add a UITexture component to it. Like this:

  1. GameObject go = new GameObject("picture" + index);
  2. go.AddComponent("UITexture");
  3.  

Now I want to assign a texture to it like this:

  1. go.GetComponent<UITexture>().mainTexture = tex;
  2.  

where tex is some Texture2D. This works fine in the editor but as soon as I test it on an Android device, it gets stuck at this point. Any ideas why?

Thanks for any help!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITexture.mainTexture causes problem on Android
« Reply #1 on: August 08, 2013, 09:29:56 AM »
"gets stuck at some point" is not very descriptive. Investigate. Where is the texture coming from? Are you downloading it? Setting the mainTexture merely sets a reference, so it won't cause it to get stuck.

Oinobareion

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: UITexture.mainTexture causes problem on Android
« Reply #2 on: August 08, 2013, 09:34:52 AM »
I load the texture from my Ressources folder:

  1. Object[] photoTextures = Resources.LoadAll("Photos", typeof(Texture2D));
  2.  

and get the textures like this:

  1. foreach (Texture2D tex in photoTextures)
  2. {
  3.   GameObject go = new GameObject("picture" + someIndex);
  4.   go.AddComponent("UITexture");
  5.  
  6.   // this is where i try to assign the texture from the Resources folder. Everything after this line does not get executed.
  7.   go.GetComponent<UITexture>().mainTexture = tex;
  8.  
  9.   ...
  10. }
  11.  
« Last Edit: August 08, 2013, 10:04:59 AM by Oinobareion »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITexture.mainTexture causes problem on Android
« Reply #3 on: August 08, 2013, 10:09:27 AM »
You have the source code for it. Open up UITexture, line 145 is the UITexture.mainTexture property. Line 151 is the setter. You have the power to put Debug.Logs in there to figure out what the issue is.