-
Notifications
You must be signed in to change notification settings - Fork 11
Improve Data Fetching in Unity #11
Comments
If I get that right, this should be up to developer and they can easily pass same filesource to all services. At least that's what I'm doing in my demos (TerrainDemoUnity branch). I also tried running everything in editor mode but as you said it doesn't work without some ugly hacks. But I think that's Unity3D's problem and we can go with them.
I totally agree on this one. People will feel lost without proper feedbacks, info etc. But that also means lots of editor script work I guess (or we can just debug.log for a while) @david-rhodes we can implement both options (coroutines and threads) as filesources right? I think we should have both options anyway. |
Sort of. I'm personally using a "singleton" FileSource, but if we add threading, I think it should be hidden from developers. They make a request through a singleton and we make a new thread if needed. Something like that.
Not sure what "go with them means." This is our problem, because we're going to want the ability to make web requests at edit time (custom editors/property drawers, etc.).
True. This would just be another implementation of |
The file source could implement a queue in this case to throttle the max number of requests. We do that on Mapbox GL Native. Often when you are zooming or panning the map, the requests in the queue are cancelled and they never really happen. We started with co-routines because it was the only way to support the WebPlayer. The interesting thing about the FileSource abstraction is that you could replace it with a ThreadedFileSource if you will never target the WebPlayer. |
In regards to the coroutines not running outside play mode here's some ways to solve it
|
Tried an easy route for a quick win via the backported Not working 😢:
|
Interesting, above error occurs with |
Argh, |
@BergWerkGIS This may be helpful: http://blog.theknightsofunity.com/using-threads-unity/ I don't know how this |
@david-rhodes thanks, also tried this (same error): foreach (var id in cover)
{
Tile.Parameters param;
param.Id = id;
param.MapId = this.mapId;
param.Fs = this.fs;
Thread worker = new Thread(getTile);
worker.IsBackground = true;
worker.Start(param);
} Reading your link now ... |
@BergWerkGIS, @parahunter suggested that the issue might be using native Unity objects that are not thread safe, such as |
@david-rhodes I now know what the problem is, it's the same like with updating those good ol' WinForms from another thread.
foreach (var id in cover)
{
Tile.Parameters param;
param.Id = id;
param.MapId = this.mapId;
param.Fs = this.fs;
Thread worker = new Thread(getTile);
worker.IsBackground = true;
worker.Start(param);
} private void getTile(object objParam)
{
Tile.Parameters param = (Tile.Parameters)objParam;
UnityEngine.Debug.LogFormat("{0}: creating T()", param.Id);
if ("0/0/0" == param.Id.ToString())
{
UnityEngine.Debug.LogFormat("{0}: aborting", param.Id);
return;
}
var tile = new T();
UnityToolbag.Dispatcher.InvokeAsync(() =>
{
UnityEngine.Debug.LogFormat("{0}: tile.Initialize", param.Id);
tile.Initialize(param, () => { this.NotifyNext(tile); });
UnityEngine.Debug.LogFormat("{0}: AFTER tile.Initialize", param.Id);
this.tiles.Add(tile);
UnityEngine.Debug.LogFormat("{0}: NotifyNext", param.Id);
this.NotifyNext(tile);
});
} |
@BergWerkGIS There's a note in that link:
Does this mean our requests are not necessarily threaded, now? Did you profile or check if there's some way to see if the tasks are in fact being threaded properly? |
@BergWerkGIS, ss part of this ticket, please keep an eye on whether it makes sense to create multiple |
With the snipped above (
Not really, but the
That's what I'm thinking too.
|
As per our scrum talk today regarding platform compatibility:
|
@tmpsantos 's comment near the top of this thread:
|
To be continued in #46 |
TL;DR
Our current Unity implementation for making web requests is quite inefficient. Let's find ways to improve it.
Possible Inefficiencies
FileSource
. This is often duplicated between objects. Unknown what the correct solution is, but probably depends on our threading options.Other Considerations
Possible Solutions
Next Steps
It would be great to have a C# expert (@BergWerkGIS, I'm looking at you) experiment in this area.
/cc @mapbox/games
The text was updated successfully, but these errors were encountered: