Unity-Technologies / com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.15k stars 435 forks source link

NetworkStart not called (for scene objects?) #32

Closed angusmf closed 6 years ago

angusmf commented 6 years ago

I have a static scene object representing an "MLAPI Room". It has a NetworkBehaviour script and the NetworkedObject script attached in the editor. The NetworkStart override never fires. It seems that it is only called from InvokeBehaviourNetworkSpawn, which only seems to be called for new players or added objects. I can't quite figure out whether "MLAPI_ADD_OBJECT" is ever sent for scene objects, but it doesn't look like it, so I assume that's why this isn't working.

I'll try testing a spawned object to verify I can get NetworkStart called on those. If so, it should be possible to work around by using the recently added NetworkingManager.OnServerStarted.

TwoTenPvP commented 6 years ago

This is only ever a problem on the server, client's should have it invoked.

Anyways, It's been resolved https://github.com/TwoTenPvP/MLAPI/commit/a0157be9dd17fb8729c8b041c23326c1112e1113

As for Clients: Every scene object is destroyed when the client starts. Then they get sent over by the server using MLAPI_ADD_OBJECT just like normal objects.

angusmf commented 6 years ago

Thanks for fixing this!

"As for Clients: Every scene object is destroyed when the client starts. Then they get sent over by the server using MLAPI_ADD_OBJECT just like normal objects."

Good to know! If HLAPI behaves this way, it's been transparent to me so far. Also, how? You wouldn't have a prefab for a random scene object.

TwoTenPvP commented 6 years ago

Good point, I didn't consider that you needed a prefab for scene objects. I will have to rethink that. But scene objects are much less important in the MLAPI as you can have one big message manager. Remember that messages can be sent to all listeners, they don't have to be targeted at a netObject.

angusmf commented 6 years ago

In this case, it would be perfectly fine for me to make it a spawned object now that I know. This may actually be the cause of my latest issue in this integration.

In general, we're just running up into some things because I'm trying to port an HLAPI integration as directly as possible to MLAPI. MLAPI will certainly enable some better design/refactoring as time goes on. Other folks will be trying HLAPI-ish stuff also. I'd be ok with just banning scene objects from the MLAPI if that makes things cleaner and you can still cover all the use cases.

TwoTenPvP commented 6 years ago

Well, I can certainly add warnings about it. But for me it only makes sense for all networked objects to be spawnable prefabs.

But I am also trying to make it very straight forward to port from HLAPI. It's one of the design goals