Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Create a custom native network plugin

Discussion in 'Multiplayer' started by unity_iKCco7B3xA1Ejg, Jun 14, 2018.

  1. unity_iKCco7B3xA1Ejg

    unity_iKCco7B3xA1Ejg

    Joined:
    Jun 14, 2018
    Posts:
    1
    Hi guys :) I'm a beginner with Unity!
    Today, I need some help to create a native plugin for implement my own network-api in C.
    Im familiar to TCP networks, and dont use the unity network API is a choice.

    My question is mostly related to the threads. My network plugin will work on another thread than the unity main thread. I heared somewhere that "unity doesn't love callbacks that happen outside its main thread, so you'll need some sort of queueing mechanism".

    Indeed, i was about to build my protocol; deserialized packets holded in structures that will be in some callback signatures. e.g void onFooBarMessage(size_t client_id, struct foo_bar_msg_t *msg). This callback will be finally defined from the unity C# and called by my network when receiving the concerned packet.

    It seems to be a bad practice for some multithread-rendering problems. So, is there anything unity built-in for that kind of problem? I discovered https://docs.unity3d.com/ScriptReference/GL.IssuePluginEvent.html that may solve the issue but, is this function callable from a native plugin ?

    My idea is to keep defining callbacks in C#, registering them into my plugin, and then execute them with IssuePluginEvent().

    Thanks. Romain
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847