I’ve tested the same package/SDK imported manually via .unitypackage file and the same error is not present.
This issue is present in both Development Builds and non-development builds.
This issue is also present in 2023.2.20. This issue is not present in 2021.3.6 but is present in 2021.3.37 so it appears as though the regression was added sometime between those two versions.
Looking at the video, this seems like an issue with the Rider debugger not displaying objects correctly. I can confirm that the version of the Rider IDE integration package has changed from 3.0.27 to 3.0.28 between the two versions, so this might be the issue. I suggest reporting this in the Code Editors & IDEs forum instead, where you are much more likely to receive help with this issue in the Rider package.
Thanks for the prompt response. It seems like you’re correct and there is an issue with the debugger that had caused me to misdiagnose the issue. However, there is still an issue with the Package Manager/Packages folder as the behaviour in my project varies significantly when the package is imported into the Packages folder by Package Manager vs manually into the Assets folder. It works in the Assets folder but not the Packages folder.
Specifically, it seems as though Json serialization is broken. I’ve tested with both JsonConvert (from Newtonsoft.Json, my preferred Json system) and JsonUtility (the Unity provided system). Both of which seem unable to serialize objects into Json on iOS when used within a script in the Packages folder. They work just fine if the script is in the Assets folder. (I’m outputting the Json string via Debug.Log now just in case the debugger won’t cooperate in case you were wondering)
Did you look at the Editor.log file to see if there’s anything informative about this (like an error/stack) that could help you figure out what could be happening. However, the video you showed is a video of Rider, not Unity. If this is a problem with the debugger in Rider, you really should reach out in that other forum I suggested, or maybe even directly reach out to JetBrains to report the issue. The Rider IDE package is distributed by Unity but maintained by JetBrains; they are the ones who can help with issues related to debugging Unity in Rider and fix any bugs in it.
Oh, sorry - one thing I might have missed/misunderstood. When you say that JSON serialization does not work, you mean that you are unable to use Debug.Log(JsonUtility.ToJson(someObject)) from a script in your package? Do you see any console log at all?
@maximeb_unity I have cross-posted on the other forum as you suggested to look into the Rider issue yes
When you say that JSON serialization does not work, you mean that you are unable to use
Debug.Log(JsonUtility.ToJson(someObject))
from a script in your package?
Yeah, if I do:
string payload = JsonUtility.ToJson(someObject);
Debug.Log(payload);
// or
string payload = JsonConvert.SerializeObject(someObject);
Debug.Log(payload);
I see “{}” get logged to the console in XCode - this also lines up with errors I see on the API level where I’m sending empty payloads in my UnityWebRequests. This happens if the script doing the serialization is in the Packages folder, but not if it is in the Assets folder.
OK that’s definitely very strange. And this happens no matter the type of the object to serialize?
At this point, for the serialization issue, I would recommend submitting bug report with a repro project attached. There might be something specifically in your project or part of your setup causing this. I would be rather surprised to find that “all JSON serialization” was broken in major LTS versions without us noticing, especially considering that JsonUtility and JsonConvert are (to my knowledge) two entirely different implementations.
After more investigation, and creation of a simple repro project, I’ve managed to get a better picture of the bug.
In both of these projects, you’ll see the Json Serialization behaviour differs. The only difference in the projects is how the package is imported (via package manager vs manually with .unitypackage file).
It seems Newtonsoft isn’t able to serialize properties with access modifiers like the popular { get; private set; }
JsonUtility still can’t handle these access modifiers in either case… Hence I tend to use Newtonsoft
I’ve also noticed that Json Deserialization seems to misbehave as well when done in a script in the Packages folder on iOS. My SDK, which uses Newtonsoft, breaks when building on iOS when loaded via Package Manager, but not when loaded into the Assets folder. This unfortunately has been more difficult to replicate with a barebones UnityPackage and project…
Either way, a packages behaviour, or any script for that matter, shouldn’t differ based on where in a project it is located (unless of course it is a path specific script: e.g. editor scripts, resource.load’ed scripts, etc.)
Absolutely, and there’s nothing in the package manager that could affect this in any way, but that said, other Unity subsystems treat assets/code from packages different ways for all sorts of reasons.