Hi all,
I’m porting our projects from Unity4 to Unity5 (webGL). We are using the pro version of the A* project. Is there a non-threaded version of the project available? Unity webGL (JS) does not support threads. Even when choosing to run without threads in my graphs the code is still creating threads (which are then no longer used). I have managed to get the games running only by commenting out these parts in the source code - which leads to others bugs in the system eventually.
Would it be possible to have a fully un-threaded version of A* so that A* is compatible with JS and webGL? Or is there some setting that I am missing which would properly disable threads?
Hi
I unfortunately do not have the Unity 5 beta yet, so I cannot test it myself.
Does it cause compilation errors or does it just fail at runtime?
And if it causes compilation errors, exactly what are the error messages?
I think it should be possible to create a version to run on JS.
Typically it causes runtime errors only.
In the AstarPath.cs Awake function graphUpdateThread will be created as a new Thread - causing a runtime exception as the creation of threads is not supported in JavaScript - even if you aren’t using multi-threading itself. Because of this exception the graph fails to initialize and is not added to the array of graphs. So whenever a Seeker tries to use StartPath it will error and the console will print “There are no graphs in the scene”. This of course causes the Seeker’s behaviour to fail.
In order to get around this I commented out all the code relating to threads. This works but unfortunately I haven’t got around to changing the GraphUpdateThread into a typical unity coroutine - which I will have to do in the future for one of our other projects as it relies on updating the graphs with new obstacles.
In addition in the JsonSerializer DeserializeMeta function there was another issue in that the ComponentModel.Converter types were being stripped out of the build so the Deserialize(typeof(GraphMeta)) was failing. This was happening even though I was not intentionally stripping any code from the build. So I had to add explicit references to all the ComponentModel.Converter types to that function to make sure they were not stripped out.
Finally a similar issue was occurring in JsonSerializer GetGraphType as the typeNames were not reflecting the assemblies of the project when built in webGL. To fix this I have been using typeof(Pathfinding.GridGraph).AssemblyQualifiedName instead of simply typeNames. I’m only supporting GridGraphs right now however.
After these fixes the pathfinding works as expected for my Seekers.
Ok, that sounds relatively easy to fix at least (compared to supporting Windows Phone 8, it sounds very easy ).
The GraphUpdateThread can be effectively bypassed by just making sure this line in the AstarPath class:
GraphUpdateThreading threading = s.order == GraphUpdateOrder.FloodFill ? GraphUpdateThreading.SeparateThread : s.graph.CanUpdateAsync(s.obj);
Gets changed to
GraphUpdateThreading threading = GraphUpdateThreading.UnityThread;
when building for WebGL.
Have you tried following the advice suggested for mobile?
http://arongranberg.com/astar/docs_dev/iphone.php
Specifically the part about the link.xml file.
Ok, not sure about the type names in JsonSerializer, I will have to look in to that in more detail when I get U5.
Ok thanks for the tips. I should be good for now but I’ll let you know if I run into anything else.