Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Unity Multiplayer GameObject Not Being Created

Discussion in 'Multiplayer' started by charlesw25, Apr 25, 2019.

  1. charlesw25


    Mar 7, 2019

    I am currently trying to make a multiplayer game using SocketIO and node.js. My main concern is that when the client socket receives my given "spawn" message(which in turn is supposed to create a GameObject for the given ID), the line will not process and no new GameObject is created. The code in question is below:

    Code (CSharp):
    1. socket.On("spawn", (data) => {
    2.                         string id = (data as JObject)["id"].ToString();
    4.                         Debug.Log("Spawning Player: " + id);
    5.                         GameObject go = new GameObject("Player ID " + id); //create object -- code halts at this point for some reason
    6.                         Debug.Log("Player Spawned: " + id);
    7.                         go.transform.SetParent(networkContainer); //add object to container
    8.                         serverObjects.Add(id,go); //add server object to dictionary
    10.                     });
    Also the code contains these imports:
    Code (CSharp):
    1. using Newtonsoft.Json;
    2. using Newtonsoft.Json.Linq;
    3. using Quobject.SocketIoClientDotNet.Client;
    4. using System;
    5. using System.Collections;
    6. using System.Threading.Tasks;
    7. using UnityEngine;
    I know the code is running because the "Spawning Player" shows up in the console yet the "Player Spawned" line doesn't.

    Any and every piece of information is appreciated!
  2. bdae


    Dec 24, 2017
    Did you ever figure this out? Having this problem right now myself.