C# NUI Help

, ,

I have recently started trying to test out NUI for more advanced UI, instead of using NativeUI or drawing using native functions, However, I don’t understand how you send NUI messages using c#, could someone help me out?

3 Likes

I am having trouble sending proper JSON thru the SendNUIMessage C# function. It keeps saying invalid format even though I think it’s not wrong.

EDIT: I was able to do it from the C# file actually. Just properly format your JSON string and send it to SendNuiMessage(). Turns out my JSON quotes weren’t properly escaped.

Here we go, try this! This worked for me! :slight_smile:

string jsonString = "{\"type\":\"enableui\",\"enable\":true}";
// send it!
API.SetNuiFocus(true, false);
API.SendNuiMessage(jsonString);
2 Likes

I have tried a bunch of different ways to do it, too. I just ended up having a separate Lua file with just the event for SendNUIMessage and triggered that from C# when I needed to.

1 Like

I’ve tried a similar thing, however I forgot to put the json values in quotes. I will see if this works for me later.