com.unity.netcode.gameobjects icon indicating copy to clipboard operation
com.unity.netcode.gameobjects copied to clipboard

Can't spawn NetworkObject - it is registered as a prefab

Open ryangarber opened this issue 5 years ago • 2 comments

Describe the bug I have a prefab registered with a NetworkObject component, and my class inherits from NetworkBehaviour. I call Instantiate({Prafab}).GetComponent().Spawn(). It fails.

To Reproduce Steps to reproduce the behavior:

  1. Create a NetworkObject.
  2. Instantiate it.
  3. Call Spawn().
  4. See pictures

Actual outcome Nothing works.

Expected outcome I can spawn a networked object.

Screenshots If applicable, add screenshots to help explain your problem.

image1 image0

Environment (please complete the following information):

  • OS: Windows 10,
  • MLAPI v0.1.0
  • Unity 2021.1.10

ryangarber avatar Jul 18 '21 02:07 ryangarber

In case you need proof that I did not mess up any configuration.

53C62F00-C2C9-4D1B-9D8F-25D95CF70985

44DC825C-F43E-40FF-AC8E-88923513469D

ryangarber avatar Jul 18 '21 02:07 ryangarber

So the issue is that GetComponentInParent() requires the GameObject to be active. Surely this should not be a requirement, and we should use GetComponent() first before falling back to Parent().

ryangarber avatar Jul 18 '21 23:07 ryangarber