Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jtcrash · Feb 22, 2012 at 12:05 AM · texturewwwloadingguitexture

Tile loading issue

HI, I am trying to load tiles into a 2D environment (orthographic), I am grabbing PNGs from the WWW and loading them into the 30 or so GUITexture objects, I am wondering if this is the most optimal way to do this (seemingly not)? As the user scrolls around, my idea is to have those textures change (so still have only 30 or so GUITexture objects just load up new textures from server). I can get them to draw, but as soon as I move around too quickly I get a "fatal error in GC: too many threads" error. Any help would be greatly appreciated!

Code for applying the texture to a tile:

 function setTexture(obj){
     url = "http://blah blah blah";
     var Download : WWW = new WWW (url);
     yield Download; // Wait for download to complete
     obj.guiTexture.texture=Download.texture;
     Download.Dispose();
 }

Jake

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Feb 22, 2012 at 12:08 AM

Can you try using less than 30? How did you arrive at that number?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by jtcrash · Feb 22, 2012 at 10:00 PM

Dave,

Really appreciate your speedy reply, let me clarify a bit further here. These tiles (and the PNGs) are 256x256, I generate the tiles based on the Screen.width and Screen.height to determine the number of tiles that are created and subsequently pulled from WWW. The generation of the prefabs only happens once (in the start()).

     var tileSize : int = 256;
     function setupGrid(){
         gridSizeX = (Screen.width / tileSize) + ((gridSizeX % 2) == 0 ? 3 : 2); // get the number of tiles required horizontally for the resolution of the game
         gridSizeY = (Screen.height / tileSize) + ((gridSizeY % 2) == 0 ? 3 : 2);
         numTiles = gridSizeX * gridSizeY; // Set the number of tiles total
         for(c = 0; c < numTiles; c++){ // Generate the appropriate number of tile prefabs
             var thisTile = Instantiate(tileObj, transform.position, transform.rotation);
             thisTile.transform.parent = tileParent;
         }
     }

Note that I am adding 2 or 3 for padding and to make sure that the grid is odd numbered so I have an exact center tile (long story). This all seems to work just fine, the clones get created in the appropriate amount, and the initial tile pull works well enough.

I did notice once I compiled that memory jumps out the roof (gets to about 300MB then I get the GC error) when I try to redraw the tiles. Basically, I figured that changing the textures again would simply overwrite the texture in memory? Is this not correct?

Here is my actual drawing function (which calls that WWW pull function setTexture from before):

 function drawTiles(x : float, y : float){
     var col = Mathf.Floor(gridSizeX / 2);
     var gu = col;
     var xcoord = -(gu * zoomLevels[zoomLevel]) + x;
     var ycoord = (gu * zoomLevels[zoomLevel]) + y;
     var tilex = -(gu * tileSize);
     var tiley = (gu * tileSize);
     for(var child : Transform in transform){
         getTileTexture(child, xcoord, ycoord, (xcoord + zoomLevels[zoomLevel]), (ycoord + zoomLevels[zoomLevel]));
         child.guiTexture.pixelInset = Rect (tilex, tiley, tileSize, tileSize);
         if(col == -gu){
             xcoord = -(gu * zoomLevels[zoomLevel]) + x;
             ycoord = ycoord - zoomLevels[zoomLevel];
             tilex = -(gu * tileSize);
             tiley = tiley - tileSize;
             col = gu;
         }else{ 
             col--;
             xcoord = -(col * zoomLevels[zoomLevel]) + x;
             tilex = -(col * tileSize);
         }
     }
 }

This function is also called from start() to begin with but then when you use the scroll wheel (to zoom, just like in google maps for example) I recall this function again in the hopes that it would re-pull the textures from the server.

     if(Input.GetAxis('Mouse ScrollWheel')){
         if(Input.GetAxis('Mouse ScrollWheel') > 0 && zoomLevel < zoomLevels.Length) zoomLevel++;
         else if(Input.GetAxis('Mouse ScrollWheel') < 0) zoomLevel--;
         drawTiles(0,0);
     }

Also, I am new to this whole unity thing and game engine developing (though I have been programming for a bit) so be easy on me :)

Thanks a lot for taking a look at this mess for me,

Jake

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

loading from disk, saving to database 0 Answers

How can I load pre-compressed textures at run-time (without using assetBundles) 3 Answers

Texture loading via www.texture not loading! 2 Answers

Large memory footprint increase when assigning a GUITexture from a WWW Object on iPad 1 Answer

GUI Textures disappearing (on buttons) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges