mapbox / mapbox-unity-sdk

Mapbox Unity SDK - https://www.mapbox.com/unity/
Other
717 stars 213 forks source link

HoloLens and MapBox issue #734

Closed nosmirck closed 5 years ago

nosmirck commented 6 years ago

At this point, everything will work in the Editor.

Trying to compile with above settings will give errors of duplicated/ambiguous use of Description Attribute.

Here is the Console Output from Compilation to Deploy and Debug the App.

wilhelmberg commented 6 years ago

@nosmirck have you set your Mapbox access token? Your log file contains:

Error setting value to 'AccessToken' on 'Mapbox.Unity.MapboxConfiguration'.

Also, have you set the Internet Capabilities`? Either in Unity or in the exported VS solution.

nosmirck commented 6 years ago

have you set your Mapbox access token?

Yes, it works fine on the Unity Editor. I did it during the step Setup Mapbox. from above

Here's a screenshot: image

Also, have you set the Internet Capabilities`? Either in Unity or in the exported VS solution.

Yes, during the step Apply all 3 options in Mixed Reality Toolkit > Configure. from above.

I re-checked the permissions on the VS project, this is what I see:

image

wilhelmberg commented 6 years ago

@nosmirck thanks for you detailed feedback. I'm able to reproduce your problem, tried with Unity@2017.4.2f this time.

I'm getting a System.Reflection.Emit is not supported error in conjunction with Mapbox.Json.Serialization. My current hunch is still the same as before: some logic is tripped by the change of how Unity now sets defines.

Mapbox.Json is branched off Newtonsoft.Json which is quite a complex piece of software so it probably will take some time to hunt down the exact location where the problem occurs - and I will get to that earliest next week as I'm busy with other stuff (new SDK release coming up πŸŽ‰).

nosmirck commented 6 years ago

@BergWerkGIS great! no problem!

For now, I've been working on the rest of the simulation using a map I saved in runtime with the editor (made the map object once loaded a fbx) and I'm cool with that for now.

Just to share a bit what I'm doing:

I'm rendering a real time map on top of a table using HoloLens. On top of the map some data will be visualized by converting the data into a heat map texture and projected on top of the MapBox based on the location.

So, in the next few weeks I'll be working with all the rest of the project with a mocked map. There's no hurry, I have exactly 4 weeks from tomorrow to finish this project (it's actually a PoC) and I'd love to include the ability to zoom the map and change location.

Thanks for the support!

Storm-Develop commented 6 years ago

Hey @nosmirck , were you able to setup project with Hololens and MapBox?

nosmirck commented 6 years ago

@YouAlwaysLoose no, I finished the rest of my PoC using a mocked map that I saved in editor runtime using this handy tool https://github.com/pharan/Unity-MeshSaver/blob/master/MeshSaver/Editor/MeshSaverEditor.cs

For the purpose of my PoC I believe I have enough, I'd like to have MapBox really load the current location and render the map properly so I can zoom in/out, change locations, etc. I'm still waiting for this bug to be fixed though.

@BergWerkGIS is there any ETA for this?

wilhelmberg commented 6 years ago

@BergWerkGIS is there any ETA for this?

Working on it, but no ETA yet. The change in Unity's behavior touches a lot more places than I had anticipated. Especially Mapbox.Json (forked from Newtonsoft.Json) is a beast to tackle.

Storm-Develop commented 6 years ago

@nosmirck Thank you for the quick reply. @BergWerkGIS Awesome I am going to wait for it too. Meanwhile, I will try to build & run the simple project involving Mapbox and Hololens. If need something to test on Hololens please let me know.

wilhelmberg commented 6 years ago

If need something to test on Hololens please let me know.

@Storm-Develop thanks, your help is very much appreciated πŸ˜„

Storm-Develop commented 6 years ago

@BergWerkGIS =) Sorry I am not that familiar with MapBox structure yet to help more. I am just trying first to make it work with the simplest solution possible. I was able to Build the project by following your #485 steps. And it works great in the Unity. However, in Hololens, I see nothing=( Seems like the map wasn't generated.

If I downgrade Unity to version 2017.1 is that going to help?

@nosmirck when you referred that map didn't render what exactly you meant? Did you see a map in HoloLens? I can't see anything except skybox. screen1

nosmirck commented 6 years ago

Exactly, the map doesn't render in the HoloLens (simulator and device) and I get the error I reported above (This is the console output) which seems to be related to the JsonSerializer @BergWerkGIS is talking about

wilhelmberg commented 6 years ago

@Storm-Develop

I was able to Build the project by following your #485 steps. And it works great in the Unity. However, in Hololens, I see nothing=( Seems like the map wasn't generated.

The problem is that Unity and HoloLens (UWP - Universal Windows Platform) are running on different .Net framework versions which offer a different set of APIs. Thus if something runs in Unity it is not for granted that the same thing will run on another platform, HoloLens in this case.

Because of the different APIs execution flow through code may follow different paths depending on the framework that's being used.

Take this simple example of string comparison: https://github.com/mapbox/mapbox-unity-sdk/blob/803b32971671ef6f743382aaca895d4e0db0935f/sdkproject/Assets/Mapbox/Core/mapbox-sdk-cs/Platform/Response.cs#L273-L279

And we have a lot of those #if/#endifs through our code.

Previously WINDOWS_UWP was defined by Unity when exporting to UWP. That seems to have changed and our code as well as 3rd party libraries (eg Newtonsoft Json) need to be changed to account for that.

If I downgrade Unity to version 2017.1 is that going to help?

Unfortunately I cannot tell: Unity's behavior has changed in one of the 2017.x releases but I don't know which as I haven't tried each and everyone.

Storm-Develop commented 6 years ago

@BergWerkGIS I see now, thank you for the detailed answer. Maybe these can be useful. https://forum.unity.com/threads/net-scripting-backend-and-visual-studio-2017-3-incompatibility.487833/#post-3191224 https://docs.microsoft.com/en-us/windows/uwp/gaming/missing-dot-net-apis-in-unity-and-uwp https://docs.unity3d.com/Manual/windowsstore-missingtypes.html So I guess the real question would be how much time it would take to fix the dependencies? I am guessing the solution could be simpler since the Unity provides the Missing .NET Types. Is it possible that it can be done sometime next week?

wilhelmberg commented 6 years ago

So I guess the real question would be how much time it would take to fix the dependencies? Is it possible that it can be done sometime next week?

@Storm-Develop I really can't tell as I'm hitting a Catch 22-like situation with a very simple problem already.

Open to suggestions how to get past that!


.NET framework version used by UWP doesn't have DescriptionAttribute so we define it ourselves and wrap it within #if UNITY_WSA:

#if UNITY_WSA
    [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
    public class DescriptionAttribute : Attribute {
        private readonly string description;
        public string Description { get { return description; } }
        public DescriptionAttribute(string description) {
            this.description = description;
        }
    }
#endif

That produces the following ambiguous reference error in Editor

 error CS0104: `DescriptionAttribute' is an ambiguous reference between
`System.ComponentModel.DescriptionAttribute' and 
`Mapbox.VectorTile.Geometry.DescriptionAttribute'

as the API of the .NET framework version used by Editor does have the DescriptionAttribute.

So we wrap our definition into #if !UNITY_EDITOR && UNITY_WSA which makes the errors in Editor disappear.

However when I try to build to Universal Windows Platform with these settings image

I get could not be found error

error CS0246: 
The type or namespace name 'DescriptionAttribute' could not be found 
(are you missing a using directive or an assembly reference?)

as we are still in Editor and #if !UNITY_EDITOR blocks our implementation but export is done using the UWP version of .NET framework which doesn't have DescriptionAttribute.

❓ ❓ ❓


My setup:

Storm-Develop commented 6 years ago

@BergWerkGIS I see what if we just comment the description text for now? Also maybe with #UNITY_WSA_10_0 it will work. OR WITH #if UNITY_WSA && ENABLE_DOTNET && !UNITY_EDITOR screenshot_19 screenshot_20

wilhelmberg commented 6 years ago

@Storm-Develop

Also maybe with #UNITY_WSA_10_0 it will work. OR WITH #if UNITY_WSA && ENABLE_DOTNET && !UNITY_EDITOR

Thanks for the ideas but I've already tried those and others (UNITY_WINRT, NETFX_CORE, ENABLE_WINMD_SUPPORT, !UNITY_EDITOR) and all possible permutations thereof.

Always the same problem: during different stages of the export Unity seems seems to use the Mono compiler and then for some other C# files the Microsoft compiler.

Also tried different runtimes and settings for the .NET Core override:

  • None: C# files are compiled using Mono compiler.
  • Use .Net Core: C# files are compiled using Microsoft compiler and .NET Core, you can use Windows Runtime API, but classes implemented in C# files aren’t accessible from the JS language. Note: when using API from Windows Runtime, it’s advisable to wrap the code with ENABLE_WINMD_SUPPORT define, because the API is only avaible when building to Universal Windows Platform, and it’s not available in Unity Editor.
  • Use .Net Core Partially: C# files not located in Plugins, Standard Assets, Pro Standard Assets folders are compiled using Microsoft compiler and .NET Core, all other C# files are compiled using Mono compiler. The advantage is that classes implemented in C# are accessible from the JS language. Note: You won’t be able to test .NET Core API in Unity Editor, because it doesn’t have access to .NET Core, so you’ll be able to test the API only when running Universal Windows App.

what if we just comment the description text for now?

Yes, I had the same idea πŸ˜„ and that got me past the first hurdle. We are heavy users of [Description()]: https://github.com/mapbox/mapbox-unity-sdk/search?q=%5BDescription%28&type=Code

Now working on module vector-tile-cs.


I'll keep this ticket updated.

wilhelmberg commented 6 years ago

@Storm-Develop @nosmirck

I think I got an initial version working and it would be great if you could give it a spin and let me know if it works for you too. Please see below for the settings I used and how to get that branch.

hololens-quest-01


My Settings

image


Branch hololens-fixes

As I've changed quite a few things (removed submodules, moved files around, ...) I suggest you clone to a dedicated local repo to avoid any conflicts:

Below command will clone just the hololens-fixes branch into a directory also called hololens-fixes:

git clone --branch hololens-fixes --single-branch --depth 1 git@github.com:mapbox/mapbox-unity-sdk.git hololens-fixes

Simple test

Open the sdkproject folder from the newly cloned repo in Unity and try to build (export) one of the examples (I went with Globe).

Don't forget to add SQLite to the main project when you build the exported project in Visual Studio:

Add Reference -> Universal Windows -> Extensions -> SQLite for Windows Universal Platform

image

Storm-Develop commented 6 years ago

@BergWerkGIS Millions of Thanks! It does work! I tried the Replace Features Example

replacefeautures

Just a small comment I didn't have SQLite for UWP so downloaded from the market place https://marketplace.visualstudio.com/items?itemName=SQLiteDevelopmentTeam.SQLiteforUniversalWindowsPlatform

wilhelmberg commented 6 years ago

@Storm-Develop Great! πŸŽ‰ πŸŽ† Now you got something to work with.

Thanks for testing πŸ™

Be aware though that this is still work in progress and might need a few more weeks till it gets into develop branch and hopefully into the next release (still a lot of cleanup necessary).

Just a small comment I didn't have SQLite for UWP so downloaded from the market place

Oh yeah, thanks for the reminder. I forgot to mention that.

timgoeij commented 6 years ago

@BergWerkGIS

I have tried the same settings as you mentioned above in my own project and in an empty project and got the same atttribute errors in Unity 2018.1.6. Is there a possibillity for my to clone the Hololens-fixes? Last time I tried to clone the branch with above command, but that it wasn't working before I wrote issue #875

Storm-Develop commented 6 years ago

@timgoeij Based on your error image you didn't get the hololens-fixes branch. Just download the branch hololens-fixes manually as zip file.

wilhelmberg commented 6 years ago

@timgoeij I agree with @Storm-Develop: looks like you didn't get the hololens-fixes branch.

Either use this git command

git clone --branch hololens-fixes --single-branch --depth 1 git@github.com:mapbox/mapbox-unity-sdk.git hololens-fixes

or download https://github.com/mapbox/mapbox-unity-sdk/archive/hololens-fixes.zip

For both options make sure you are using a new target directory and not save/clone into an existing (SDK) one, which might also lead to those errors.

mayank-technical commented 6 years ago

@BergWerkGIS You are amazing. Thanks for great help . I am able to run all the samples of mapbox. Thanks a ton.! Just need to know how you people record hololens screen?

wilhelmberg commented 6 years ago

Thanks @mayank-technical πŸ™

Just need to know how you people record hololens screen?

By hitting Record in the Device Portal πŸ˜„: https://docs.microsoft.com/en-us/windows/mixed-reality/using-the-windows-device-portal#mixed-reality-capture

mayank-technical commented 6 years ago

Thanks a lot William.!! :)

On Mon 9 Jul, 2018, 5:31 PM Wilhelm Berg, notifications@github.com wrote:

Thanks @mayank-technical https://github.com/mayank-technical πŸ™

Just need to know how you people record hololens screen?

By hitting Record in the Device Portal πŸ˜„:

https://docs.microsoft.com/en-us/windows/mixed-reality/using-the-windows-device-portal#mixed-reality-capture

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mapbox/mapbox-unity-sdk/issues/734#issuecomment-403455451, or mute the thread https://github.com/notifications/unsubscribe-auth/AFbM3OpwyzkDoAa_mDrEdM522jyeOAkTks5uE0YbgaJpZM4TzDV_ .

emartinDesignInteractive commented 6 years ago

Is there any update on when this will be rolled up? Creating a cross platform app for mobile and hololens using World Scale AR. Thanks!

wilhelmberg commented 5 years ago

@emartinDesignInteractive PR is up https://github.com/mapbox/mapbox-unity-sdk/pull/945 but not yet merged.

BrentKingma commented 5 years ago

@BergWerkGIS hey, thanks for the work that you have been doing but do you know how long it will be for the mapbox to work with unity's il2cpp compiler?

wilhelmberg commented 5 years ago

Closing - PR #945 UWP fixes (and more) was merged.

NOTE: UWP (Desktop, HoloLens, Windows Phone, ...) builds with Scripting Backend: IL2CPP still don't work - only .NET backend does. Blocker here is https://github.com/mapbox/Mapbox.Json-unity (a fork of Newtonsoft.Json) which emits dynamic compiler code which does not work with IL2CPP.

LukeHackett12 commented 5 years ago

Hi, I was wondering if this is still an ongoing issue. I am attempting to use mapbox on hololens and have tried everything in this thread and I still get this error:

Exception thrown: 'SQLite4Unity3d.SQLiteException' in Assembly-CSharp.dll
error:14090086:lib(20):func(144):reason(134)
Setting up 1 worker threads for Enlighten.

  Thread -> id: 634 -> priority: 1 

Mapbox.Unity.MapboxAccess+InvalidTokenException: StatusNotYetSet

Any help would be appreciated!

Toducs commented 5 years ago

Hi, I was trying the same and after digging for a few hours... i found that the problem is that the PRAGMA command send to the sqlite was actually returning a row, and because it get executed with ExecuteNonQuery command it was not expecting a row results, what cause raise the error. I was able to pass that by chaging the line 2152 of the \Assets\Mapbox\Core\mapbox-sdk-cs\Platform\SQLite\SQLite.cs file as if (r == SQLite3.Result.Done || r == SQLite3.Result.Row). However now I have other problem and is that for some reason the webrequest to get the token is not working. It seem to be related to the UnityWebRequest getting Unknow error... I am trying to figure it out.

LukeHackett12 commented 5 years ago

You have to substitute unityWebRequests with normal c# HttpRequests, at least that's what I've done elsewhere and it's worked to get Web information.

Toducs commented 5 years ago

Hooo that make sense. Thank you very much.

lukemadera commented 3 years ago

@BergWerkGIS Thanks for your work on this; any update on IL2CPP, or is Mapbox still not usable for UWP?

NHarishGit commented 2 years ago

UNITY 2019.4.31f with MAPBOX v2.1.1 SDK, still the same errors, cannot build for UWP with I2LCPP (mandated by UNITY):

"Assets\Mapbox\Core\mapbox-sdk-cs\MapMatching\MapMatchingParameters.cs(15,4): error CS0104: 'Description' is an ambiguous reference between 'Mapbox.VectorTile.Geometry.DescriptionAttribute' and 'System.ComponentModel.DescriptionAttribute'"

Any one has taken an effort to fix it or a WorkAround for now ?

emartinDesignInteractive commented 2 years ago

UNITY 2019.4.31f with MAPBOX v2.1.1 SDK, still the same errors, cannot build for UWP with I2LCPP (mandated by UNITY):

"Assets\Mapbox\Core\mapbox-sdk-cs\MapMatching\MapMatchingParameters.cs(15,4): error CS0104: 'Description' is an ambiguous reference between 'Mapbox.VectorTile.Geometry.DescriptionAttribute' and 'System.ComponentModel.DescriptionAttribute'"

Any one has taken an effort to fix it or a WorkAround for now ?

Would recommend looking into Microsoft's Maps for Unity plugin, depending on your use case.

https://github.com/microsoft/MapsSDK-Unity

tvasilopoulou commented 2 years ago

Hello everyone, I have been trying to load a simple map prefab using Mapbox with:

I have also deleted all AR related directories from the mapbox package and set all "Description" occurrences to refer to System.ComponentModel. In MapboxAccountsUnity.dll, I have checked the WSAPlayer checkbox in the inspector panel. Finally, after building for UWP as shown in the picture below, I have added the SQLite reference. Screenshot_30

I have the same problem as @nosmirck described in https://github.com/mapbox/mapbox-unity-sdk/issues/734#issuecomment-395201914, meaning I can successfully deploy to Hololens but on Debug mode I get similar logs as shown here:
20211117_122503_HoloLens

Most important error in the logs is: Rethrow as JsonSerializationException: Error setting value to 'AccessToken' on 'Mapbox.Unity.MapboxConfiguration'. at Mapbox.Json.Serialization.ExpressionValueProvider.SetValue

but the token I provide in the editor is valid. In the Project settings my Scripting backend in IL2CPP which I cannot change but the API compatibility level is .NET 4.x.

Does anyone know how I can manage rendering the map on Hololens and resolving the NullReferenceException? Thank you!

mertusta1996 commented 2 years ago

For Hololens-2 and Mapbox in Unity UWP, try this repo ; https://github.com/mertusta1996/Mapbox-Hololens-2-Unity-UWP-

NHarishGit commented 2 years ago

For Hololens-2 and Mapbox in Unity UWP, try this repo ; https://github.com/mertusta1996/Mapbox-Hololens-2-Unity-UWP-

The link is NOT working for me

mertusta1996 commented 2 years ago

For Hololens-2 and Mapbox in Unity UWP, try this repo ; https://github.com/mertusta1996/Mapbox-Hololens-2-Unity-UWP-

The link is NOT working for me

I fixed the link sorry πŸ‘ https://github.com/mertusta1996/Mapbox-Hololens-2-Unity-UWP-