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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

5.2.1p3 SpawnWithClientAuthority and ReplacePlayerForConnection Crash Unity (windows 7)

Discussion in 'Multiplayer' started by awwolfe, Oct 12, 2015.

  1. awwolfe

    awwolfe

    Joined:
    Sep 22, 2013
    Posts:
    27
    on a player object spawned by the networkmanager or from the derived networkmanager (I tried doing it from both classes), I call a CmdSpawnPlayer that I want to spawn a different, new object for the player.

    I've tried SpawnWithClientAuthority (wanting the player to control the two objects) --didn't work and tried ReplacePlayerForConnection thinking maybe there was some issue with the client only being able to control 1 object (though I thought it should be able to have authority over more than 1.

    Both crash unity to the desktop using the only minor tweaks from the sample in the docs...

    Am I missing something or is this a bug with patch (Access Violation)? Obviously Unity shouldn't crash to the desktop even if I made a mistake, but am I approaching the problem correctly? What else can I try?

    Thanks....

    public class Player:NetworkBehaviour{
    ...

    void SpawnPlayerObject()
    {
    if(isLocalPlayer)
    {
    CmdSpawnPlayerObject(playerObjectPrefab)
    }
    }

    [Command]
    void CmdSpawnPlayerObject(GameObject playerObject)
    {
    //playerObject is a prefab with a NetworkIdentity with "localAuthority" and the item is registered with the NetworkManger in the editor

    GameObject go =Instantiate (playerObject);

    NetworkServer.SpawnWithClientAuthority(go, connectionToClient);//debuggin shows this line always crashes Unity.. connectionToClient="hostId: -1 connectionId: -1 isReady: True channel count: 0"...go is a non-null valid object
    }

    }
     
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    "playerObject" will be null CmdSpawnPlayerObject in your pasted code. Passing a prefab in a command that like wont work.

    yes, it should not crash the editor..
     
  3. awwolfe

    awwolfe

    Joined:
    Sep 22, 2013
    Posts:
    27
    Thanks for the response. This is driving me nuts, so I am appreciative of any help.


    I was following the code in VS debugger, so seems like a misunderstanding somewhere (not sure why you are saying the playerObject will be null)
    VS debugger:The GameObject "playerObject" is not null in the Cmd function. The GameObject "go" is also not null after the Instantiate, when I call the SpawnWIthClientAuthority. I thought it would have to do with the hostId=-1 and/or connectionId=-1...seems like those should be non -1 integers for a valid value.


    I've been trying this in a hosted network...so maybe on a remote->server cmd you can't pass a gameObjectPrefab? However, see below....

    Think player pet. What I want is the player to tell the server to spawn a 'pet' that the player will also have control of. I've also tried using a GameObject property directly in the player class instead of passing it in through the Cmd function. It again creates a valid GameObject in the Instantiate function, but then continues to crash Unity with the SpawnWithClientAuthority.
     
  4. awwolfe

    awwolfe

    Joined:
    Sep 22, 2013
    Posts:
    27
    If I simply NetworkServer.Spawn(go); Unity locks up (doesn't crash, locks up. unresponsive). I've tried submitting a bug through FogBugz system, but it never showed up. 5.2.1f had a lot of issues with the HL networking that I was running into, but not like this. I am sure this has to be a Unity bug and will get fixed as long as someone there knows about it.
     
  5. awwolfe

    awwolfe

    Joined:
    Sep 22, 2013
    Posts:
    27
    Ok, so I stripped down the object I was trying to instantiate to nothing but an empty gameobject and it spawned without crashing. I added one component back at a time to rebuild the prefab into exactly what I had before and it will spawn without crashing or locking up now...so I would guess the prefab data was corrupt or something.

    It doesn't seem to be spawned with clientauthority however. But that is likely in need of a new thread.