Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by kilianbaur · Dec 22, 2015 at 08:56 AM · unity 5networkingbuildclienthost

Starting a client on standalone.exe not working but i works on editor play

This code snippet here causes the error below the code only on standalone exe. What could be the proleme? Thanks for help.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Networking;
 using UnityEngine.UI;
 
 public class MyNetworkManager : NetworkManager
 {
     public bool isAtStartup = true;
     void Update()
     {
         if (isAtStartup)
         {
             if (Input.GetKeyDown(KeyCode.X))
             {
                 SetPort();
                 StartServer();
                 StartClient();
    //             StartHost();            // same error for startclient() or starthost()
                 isAtStartup = false;
             }
         }
     }
 }

NullReferenceException: Object reference not set to an instance of an object at UnityEngine.Networking.NetworkTransform.SerializeMode3D (UnityEngine.Networking.NetworkWriter writer) [0x0005c] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkTransform.cs:251

at UnityEngine.Networking.NetworkTransform.OnSerialize (UnityEngine.Networking.NetworkWriter writer, Boolean initialState) [0x0005a] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkTransform.cs:195

at UnityEngine.Networking.NetworkIdentity.UNetSerializeAllVars (UnityEngine.Networking.NetworkWriter writer) [0x00010] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkIdentity.cs:421

at UnityEngine.Networking.NetworkServer.SendSpawnMessage (UnityEngine.Networking.NetworkIdentity uv, UnityEngine.Networking.NetworkConnection conn) [0x000d0] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkServer.cs:1403

at UnityEngine.Networking.NetworkServer.ShowForConnection (UnityEngine.Networking.NetworkIdentity uv, UnityEngine.Networking.NetworkConnection conn) [0x0000b] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkServer.cs:1202

at UnityEngine.Networking.NetworkConnection.AddToVisList (UnityEngine.Networking.NetworkIdentity uv) [0x0000d] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkConnection.cs:497

at UnityEngine.Networking.NetworkIdentity.AddObserver (UnityEngine.Networking.NetworkConnection conn) [0x000b9] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkIdentity.cs:715

at UnityEngine.Networking.NetworkServer.SetClientReadyInternal (UnityEngine.Networking.NetworkConnection conn) [0x001cb] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkServer.cs:1191

at UnityEngine.Networking.NetworkServer.SetClientReady (UnityEngine.Networking.NetworkConnection conn) [0x00000] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkServer.cs:1125

at UnityEngine.Networking.NetworkManager.OnServerReady (UnityEngine.Networking.NetworkConnection conn) [0x00024] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkManager.cs:772

at UnityEngine.Networking.NetworkManager.OnServerReadyMessageInternal (UnityEngine.Networking.NetworkMessage netMsg) [0x00014] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkManager.cs:653

at UnityEngine.Networking.NetworkConnection.HandleReader (UnityEngine.Networking.NetworkReader reader, Int32 receivedSize, Int32 channelId) [0x0011f] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkConnection.cs:416

at UnityEngine.Networking.NetworkConnection.HandleBytes (System.Byte[] buffer, Int32 receivedSize, Int32 channelId) [0x00007] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkConnection.cs:372

at UnityEngine.Networking.NetworkConnection.TransportRecieve (System.Byte[] bytes, Int32 numBytes, Int32 channelId) [0x00000] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkConnection.cs:522

at UnityEngine.Networking.NetworkServer.InternalUpdate () [0x0020b] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkServer.cs:702

at UnityEngine.Networking.NetworkServer.Update () [0x0000c] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkServer.cs:564

at UnityEngine.Networking.NetworkIdentity.UNetStaticUpdate () [0x00000] in C:\buildslave\unity\build\Extensions\Networking\Runtime\NetworkIdentity.cs:909

(Filename: C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkTransform.cs Line: 251)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Dec 02, 2016 at 09:55 PM

You can't be client and server at the same time. This is a special case and is called "Host".

  • Use StartServer if this PC should be a dedicated server

  • Use StartHost if this PC should be a server as well as a client.

  • Use StartClient if this PC should by a client.

Never use two of those methods in the same application.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by mercior · Nov 15, 2016 at 09:00 AM

I fixed the same error - I had a UNET build which worked as server in the editor but did not work when built as standalone.

The problem for me was that I had an object that disabled itself in OnStart() which contained objects that had NetworkIdentities.

I don't 100% understand why, but when building standalone those objects are cached by the server before Start() is called and then they are attempted to be transmitted to clients, but the server produces this error because he objects are no longer active.

It can help to use the line

 LogFilter.currentLogLevel = (int)LogFilter.FilterLevel.Debug;

in a Start() somewhere (eg your NetworkManager) to get more debug info out of UNET. This is what led me to find out what was going on.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image indgaming · Dec 02, 2016 at 05:20 AM 0
Share

I am having the same issue, except I am not disabling any objects at all. All I am doing is starting the server with match$$anonymous$$aker.Create$$anonymous$$atch() after enabling matchmaker like I have before in other projects. The only difference is I am doing this all in the start() method.

I tried calling Create$$anonymous$$atch() in the Update() method on a mouse button trigger and it is causing the same issue. This is only happening in the builds and not the editor. The problem doesnt occur when I use the "stock" UNET Network HUD, but I want the game to connect/host when the game starts up.

avatar image indgaming indgaming · Dec 02, 2016 at 09:26 PM 0
Share

EDIT: I think I fixed the issue. The problem seemed to be because the game was using the same scene for Online AND Offline, and that scene had an object with a NetworkIdentity. So it was probably an issue for Offline mode. I fixed it by creating an offline scene as a "Loading/Connecting" screen

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Object not updating on host 1 Answer

How can a client connect more players to a network game? 1 Answer

NETWORKING: Start as Host if no Host; Otherwise Start as Client 0 Answers

Building Client and Server apps from single project 1 Answer

unity netcode object doesnt get declared on client when instantiated 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges