Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Unity3d Engine support #1440

Open
superarchi opened this issue Sep 21, 2017 · 12 comments · May be fixed by #2044
Open

Add Unity3d Engine support #1440

superarchi opened this issue Sep 21, 2017 · 12 comments · May be fixed by #2044

Comments

@superarchi
Copy link

superarchi commented Sep 21, 2017

Can you add Unity3d Engine supporting? https://unity3d.com/

@McMuzzle
Copy link

i'm using this tool in unity with no problem, what needs to be done? Are you talking of scene serialization?

@superarchi
Copy link
Author

But it's not works on iOS with AOT (unity3d with IL2CPP)
You can read about problem here https://github.com/SaladLab/Json.Net.Unity3D :)

@jdnichollsc
Copy link

+1 Any plans to support Unity?
Thanks in advance guys

@richfuns
Copy link

Wish to support latest unity3d perfectly.

@dngulin
Copy link

dngulin commented Oct 13, 2018

The Unity 2018 has an API capability with the .NET Standard 2.0. You also can get a Json.NET nuget package that contains .NET Standard 2.0 version (see Dependencies).

@dzmitry-lahoda
Copy link

I may not still run under IL2CPP for Android or iOS even if .NET Standard 2.0.

@dngulin
Copy link

dngulin commented Oct 17, 2018

I have manually built Json.Net 11.0.2 for Unity 2017 with small code changes. And now it works on iOS.

What i've changed:

  1. Checkout tag 11.0.2
  2. Recreate Newtonsoft.Json.csproj with Rider (because of Mono doesn't support msbuild 15, only 14)
  3. Set traget framework to .NET Framework 4.6.2
  4. Force set project language version to C# 7.0
  5. Break all C# 7.2 features (readonly struct -> struct), because of Mono doesn't support that
  6. Copy define symbols from original netstandard2.0 target and remove what is not supported.
  7. Add new define symbol UNITY_LTS to use ReflectionValueProvider and LateBoundReflectionDelegateFactory
  8. ???
  9. PROFIT!

You can apply this patch on tag 11.0.2 and test it on iOS. In my case everything works good (for save back-end and RPC requests serialization).

Used define symbols:

UNITY_LTS;HAVE_ADO_NET;HAVE_APP_DOMAIN;HAVE_ASYNC;HAVE_BINARY_FORMATTER;HAVE_BINARY_SERIALIZATION;HAVE_BINARY_EXCEPTION_SERIALIZATION;HAVE_CHAR_TO_LOWER_WITH_CULTURE;HAVE_CHAR_TO_STRING_WITH_CULTURE;HAVE_COM_ATTRIBUTES;HAVE_COMPONENT_MODEL;HAVE_CONCURRENT_COLLECTIONS;HAVE_COVARIANT_GENERICS;HAVE_DATE_TIME_OFFSET;HAVE_DB_NULL_TYPE_CODE;HAVE_DYNAMIC;HAVE_EMPTY_TYPES;HAVE_ENTITY_FRAMEWORK;HAVE_EXPRESSIONS;HAVE_FAST_REVERSE;HAVE_FSHARP_TYPES;HAVE_FULL_REFLECTION;HAVE_GUID_TRY_PARSE;HAVE_HASH_SET;HAVE_ICLONEABLE;HAVE_ICONVERTIBLE;HAVE_INOTIFY_COLLECTION_CHANGED;HAVE_INOTIFY_PROPERTY_CHANGING;HAVE_ISET;HAVE_LINQ;HAVE_MEMORY_BARRIER;HAVE_METHOD_IMPL_ATTRIBUTE;HAVE_NON_SERIALIZED_ATTRIBUTE;HAVE_READ_ONLY_COLLECTIONS;HAVE_SECURITY_SAFE_CRITICAL_ATTRIBUTE;HAVE_SERIALIZATION_BINDER_BIND_TO_NAME;HAVE_STREAM_READER_WRITER_CLOSE;HAVE_STRING_JOIN_WITH_ENUMERABLE;HAVE_TIME_SPAN_PARSE_WITH_CULTURE;HAVE_TIME_SPAN_TO_STRING_WITH_CULTURE;HAVE_TIME_ZONE_INFO;HAVE_TRACE_WRITER;HAVE_TYPE_DESCRIPTOR;HAVE_UNICODE_SURROGATE_DETECTION;HAVE_VARIANT_TYPE_PARAMETERS;HAVE_VERSION_TRY_PARSE;HAVE_XML_DOCUMENT;HAVE_XML_DOCUMENT_TYPE;HAVE_CONCURRENT_DICTIONARY

@squibel
Copy link

squibel commented Jan 10, 2019

Version 12.0.1 works in Unity 2018.3 out of the box, but fails when building with IL2CPP. I get a nullreference exception when trying to deserialize a string. The workaround of @dngulin will probably work (I haven't tested it yet) but is rather cumbersome when you want to update the Json.NET package in Unity3d each time a new version is released.
Are there any plans to add @dngulin's changes to the main Json.Net Nuget package so it has Unity3d IL2CPP support out of the box?

@dzmitry-lahoda
Copy link

dzmitry-lahoda commented Jan 10, 2019

@squibel IL2CPP does LINQ interpretation. MONO does LINQ compilation. JSON uses LINQ to be faster. But JSON can use reflection only. I guess @dngulin did that - reflection with Unity specific hacks. Other option is to Unity to fix bugs in LINQ interpretation (I raised a bug for that but not yet provided sample). Here is sampe for binary MessagePack-CSharp/MessagePack-CSharp#338 . So bug is in Unity. Not in JSON.NET. But JSON.NET could be changed to avoid bug in Unity.

@squibel
Copy link

squibel commented Jan 10, 2019

@dzmitry-lahoda So if I understand correctly Unity should fix their IL2CPP LINQ interpretation or a workaround could be built into Json.NET to avoid the Unity bug.
I already filed a bug report with a repro project attached, so let's hope Unity will reply soon.

@applejag
Copy link

applejag commented Apr 12, 2019

@squibel commented on 10 Jan

Version 12.0.1 works in Unity 2018.3 out of the box, but fails when building with IL2CPP. I get a nullreference exception when trying to deserialize a string. The workaround of @dngulin will probably work (I haven't tested it yet) but is rather cumbersome when you want to update the Json.NET package in Unity3d each time a new version is released.
Are there any plans to add @dngulin's changes to the main Json.Net Nuget package so it has Unity3d IL2CPP support out of the box?

I tried it personally and gotta say love it that it actually works. Been searching for a solution for a while and finally, at least a workaround. Sucessfully using Json.NET 12.0.1 in WebGL.

I can try submitting it as an extra build via PR. Then let's hope it gets added so the steps dont have to be repeated by everyone selves.

@kstreichergb
Copy link

Version 12.0.1 works in Unity 2018.3 out of the box, but fails when building with IL2CPP. I get a nullreference exception when trying to deserialize a string. The workaround of @dngulin will probably work (I haven't tested it yet) but is rather cumbersome when you want to update the Json.NET package in Unity3d each time a new version is released.
Are there any plans to add @dngulin's changes to the main Json.Net Nuget package so it has Unity3d IL2CPP support out of the box?

Everything in the editor always runs under Mono and never uses IL2CPP, that is why it works in the editor and fails during the IL2CPP build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants