Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NRE in [SyncVar] NetworkIdentity when set for a newly instantiated GameObject #399

Closed
OneFirefly opened this issue Oct 16, 2020 · 1 comment · Fixed by #400
Closed

NRE in [SyncVar] NetworkIdentity when set for a newly instantiated GameObject #399

OneFirefly opened this issue Oct 16, 2020 · 1 comment · Fixed by #400
Labels

Comments

@OneFirefly
Copy link

OneFirefly commented Oct 16, 2020

Describe the bug
Instantiating a go, setting a [SyncVar] NetworkIdentity on one of its components, and then Using Server.Spawn(go); causes NullReferenceException

System.NullReferenceException: Object reference not set to an instance of an object
at Mirror.NetworkBehaviour.GetSyncVarNetworkIdentity (System.UInt32 netId, Mirror.NetworkIdentity& identityField) [0x00011] in C:\Unity\MirrorNG - SyncVar initialization bug\Assets\Mirror\Runtime\NetworkBehaviour.cs:397 
at TestComp.get_NetworkIdentity () <0x1756d80e490 + 0x00072> in <157148441a354f5e811588a77f5b3f35>:0 
at TestComp.set_NetworkIdentity (Mirror.NetworkIdentity value) [0x0000d] in <157148441a354f5e811588a77f5b3f35>:0 
at Test.TestSpawn () [0x0000d] in C:\Unity\MirrorNG - SyncVar initialization bug\Assets\Test.cs:33 

To Reproduce

  • Create a server in Host mode
  • Spawn a GameObject - use NetworkServer.Authenticated UnityEvent to call the spawn function:
//code in spawn function
var go = GameObject.Instantiate(prefab);
go.GetComponent<TestComp>().Identity = NetIdentity;
Server.Spawn(go);
  • press Play and check Console for NRE

Desktop (please complete the following information):

  • OS: Windows
  • Build target: Unity Editor
  • Unity version: 2019.4.10f1
  • MirrorNG version: v49.2.1

Additional context
The problem is the same with a remote client instead of host mode

paulpach added a commit that referenced this issue Oct 16, 2020
github-actions bot pushed a commit that referenced this issue Oct 16, 2020
## [49.3.3](v49.3.2...v49.3.3) (2020-10-16)

### Bug Fixes

* reading and writing a network identity before spawning ([#400](#400)) ([870f49d](870f49d)), closes [#399](#399)
@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 49.3.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant