1 (edited by jhcom 2020-04-30 17:14:55)

Topic: Maps huge memory usage

Hey, maybe I am doing something wrong, but the maps seems really unclear for me.

When zooming, memory usage keeps increasing and doesn't decrease. Street names are clear on load, bu on moving or zooming they become blurry as you can see in the attached photo.

I read on a different post that increasing cache size helps, so I did that, but to no prevail. My current settings are:

google maps, terrain
I tried create texture at 2048x2048, now I put it back to 512x512.
With memory cache on, memory keeps increasing on scrolling till the device is out of memory
Dache mb = 120, unload 30
Memory cache 60, unload 30
API key put in
Total of 5 custom markers which consist out of a few images and no update methods

If I remove memory cache, then it remains around 501mb total, but the streets are still very unclear. I am using unity 2020.1

Do you have some recommendation for settings?

Kind regards,

Julian

Post's attachments

Attachment icon IMG_4385.png 365.08 kb, 56 downloads since 2020-04-30 

Re: Maps huge memory usage

Hello.

1. In 99% of cases, you must use tileset control.
Tileset has much better performance, uses less memory, and has many exclusive features.
In your screenshot, I do not see anything that forces you not to use tileset.
2. A map on texture of 512x512 cannot use 500 megabytes.
This is too much, even for 2048x2048.
How did you find this value?
3. To make the map automatically center on the screen, use Tileset + Camera Orbit.
4. To adjust the size of the map to fit the screen, use Adjust to Screen.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Maps huge memory usage

Hey Alex,

Thank you for the quick response! I have a 2D game, so I thought I would use it in 2D, tileset was only in 3D available. I'll try to convert it to tileset/3D. The map is only part of the game, so I need it to be loaded on a tab and also start the load there.

I found it with an xcode Build/Run when I kept scrolling ons the map, I saw in xcode that memory kept increasing and never dropped down.

Kind regards,

Julian

4 (edited by jhcom 2020-05-01 15:45:07)

Re: Maps huge memory usage

Managed to switch it to 3D, worked much better with loading and memory! Still quite a lot, but I can tweak that. I do have a question though. Why are the points transforms updating when using the custom marker example script? If I load 100 points all these transforms have to be updated at the same time for each layer of the prefab as I scroll. Is this the only way how this can be implemented?

Re: Maps huge memory usage

Xcode shows you the overall memory usage of an application that also includes Unity Engine itself and your assets.
So here to say that the map uses 500 megabytes - this is not correct.

Tileset may be different.
Set the camera perpendicular to the map and it will look like a 2D map.
Or you can use Render Texture to display the map on UI.
Online Maps v3.8 will have an example for this.

Unfortunately, I did not understand your questions about custom markers.
Please rephrase this.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Maps huge memory usage

Ah the memory usage on xcode only went up as I was scrolling through the map, it's reproducible on an empty project with just maps v3 implemented.

Basically as you navigate the map, all map points need ui updates. Let's say you have a marker gameobject with a rect transform and an image inside of it. That's 2 rect transforms total. This means that as you navigate the map, all markers need a transform update times 2. If you have 100 objects in the map, you need 200 transform updates. It's just how the unity ui works. I don't think it's possible to fix this though. This guy from unity explains it much better than me:
https://www.youtube.com/watch?v=_wxitgdx-UI&t=1558s

I was just curious if there was a method to not have all the points getting dirty and updating themselves as you scroll the map, but I don't think it's possible. The only method I can think of is to keep the map in a bigger size and move a scroll rect above it instead of the map itself, but then you can't zoom in. Like this you can put 1000 points and scroll with no spikes, but no zooming. 

Thank you so much for answering my questions and helping me out! Have a great day.

Julian

Re: Maps huge memory usage

Thanks for the video, it is very useful.
But, unfortunately, this is not particularly applicable here, because in addition to zoom, you need to keep in mind:
- jump through 180 meridian;
- changing the position and / or size of the map in the scene;
- changing the position of the camera (for example, when you rotate or tilt the camera using Camera Orbit);
- updating elevation data.

This can be implemented in specific projects when you know for sure that these situations will never happen in your case.
But to make a general example that will use these optimizations is not possible, because immediately there is someone who will say that this does not work for him because of something.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Maps huge memory usage

Yeah, thought the same, was just curious about it! Thank you for all the responses!

Re: Maps huge memory usage

Hi!
1. I have the same problem in my case:
Tileset control is used.
512 x 512 tiles are used, texture compression is disabled.

At the moment the memory cache decided it filled 10 MB Unity profiler shows growth of about 600 MB in textures.
What i've tried (did not help):
- set memory caches size to 1 / 50 / 150 / 200 MB;
- temporary change the size constant in MemoryCacheItem from 30 000 to 1 000 000;
- set Online Maps : Advanced : Count Parent Levels from 5 to 0.

Also the problem is reproducible in an empty project:
- create an empty Unity project;
- call GameObject -> Infinity Code -> Online Maps -> Map Wizard;
- check Move camera to Map, press Fix camera near, far.
- chose OpenStreetMap:Mapnik;
- press Create;
- play in Unity editor and start continuously zooming in and out while watching the Unity profiler : Memory : Textures.
It starts from 100 MB, grows to 200 MB and drops to 170 MB on memory cache clearing. But suddenly starts to grow indefinitely (was able to get to 500+ MB).
The same bug is also reproducible in case of default (in wizard) map provider ArcGIS (Esri):WorldImagery but requires to zoom longer.

2. Connected question about memory:
Disabling the map GameObject while zoom == 1 leaves the map on the minimum level of textures memory consumption. But it is not the case if disabling while zoomed in.
I'm setting zoom = 1 on the next map GameObject activation. And it resets memory to the minimum level. But setting zoom == 1 in OnDisable() does not free memory.
I would like to leave the map on the minimum memory level in every case when I do not need the map and disable the map GameObject.
What i've tried to call in OnDisable() (did not help):
- set zoom = 1;
- call OnlineMapsCache.ClearMemoryCache();
- call OnlineMaps.tileManager.Reset();
Also tried to destroy and recreate the map GameObject from prefab (instead of disabling) every time I need it. But it increases textures memory for about 2 MB on every creation.

Re: Maps huge memory usage

Hi.

1. This difference happens because the cache counts the size of the average tile image (png, ~30 kb), but not its texture in memory (~1 mb for uncompressed, ~131 kb for compressed).
I realise this is not entirely logical, but unfortunately it's too late to change this, because this change will affect existing user projects.
I'll think about how to describe it so it doesn't confuse users.

The way with increasing the constant and setting the appropriate cache size works well.
But, the thing to keep in mind here is that the profiler also shows the editor textures.
In my case, this increases the displayed value by almost 100 mb.

2. This is because using tileManager.Reset() only marks tiles unused.
In a normal usage scenario, the tiles are destroyed later.
Because you have disabled the map GameObject, its LateUpdate is no longer called, and there is no destruction of tiles until you enable the map again.
To work around this after Reset() call tileManager.UnloadUnusedTiles().

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

11 (edited by denis 2024-04-02 15:20:14)

Re: Maps huge memory usage

Thank you for the answers!
1. I just mean that there is a probability of infinite memory growth right out of the box (when memory cache is enabled).
2. tileManager.UnloadUnusedTiles() actually helped. Thanks!