79753148

Date: 2025-09-02 06:40:42
Score: 0.5
Natty:
Report link

This is because you can only Instantiate a GameObject on unity's main thread and the message you receive calls your handler code on an async thread.

I would recommend looking at the UnityMainThreadDispatcher package to help with this.

A simple but less efficient method to fix this would be to have a bool that is set true in your handler. Then in update function if that bool is true, Instantiate your GameObject.

    void Start()
    {
        EventHandler<MsgHandlerEventArgs> handler = (sender, args) =>
        {
            messageReceived = true;
        };

    // Update is called once per frame
    void Update()
    {
       if(messageReceived)
        // create object 
    }
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: user31401452