Question by
Boudewijn · Apr 01 at 09:45 AM ·
c#javascriptwebglsendmessagesend message
How to retrieve nested JSON variable - sendMessage WebGL
Hello! How can I retrieve a nested object in Unity with JsonUtility. I have something like this in javascript:
grid = {
type: "frame",
layer_1: { "height": 100, "numberOfComponents": 3 },
layer_2: { "height": 200, "numberOfComponents": 7 },
};
UNITY_INSTANCE.SendMessage('Landscape', 'SetGrid', JSON.stringify(grid));
and in Unity:
[HideInInspector]
public string type;
public void SetGrid(string data)
{
JsonUtility.FromJsonOverwrite(data, this);
Debug.Log(type); //frame
So type works but how to get
layer_1['height']
Comment
Your answer
Follow this Question
Related Questions
Storing timetstamp when building for WebGL with C# 0 Answers
What's the proper way to make my game listen to a browser's javascript event? 0 Answers
Unity 2020.1 sendMessage no longer works from browers JS 1 Answer
Java Script to talk to C# script 0 Answers
Error in BUILD with UnityWebRequest but not in Editor 0 Answers