Search Unity

GameObject Not Being Created

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

  1. charlesw25

    charlesw25

    Joined:
    Mar 7, 2019
    Posts:
    1
    Hello,

    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();
    3.  
    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
    9.                    
    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

    bdae

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