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

OnValidate logs an error if NetworkIdentity was added after other NetworkBehaviors #3819

Closed
ArturMoczulski opened this issue May 3, 2024 · 3 comments

Comments

@ArturMoczulski
Copy link

ArturMoczulski commented May 3, 2024

Describe the bug
NetworkBehaviors throw error message Mirror.NetworkTransformReliable on Spine requires a NetworkIdentity. Please add a NetworkIdentity component to Spine or it's parents. even though the game object has NetworkIdentity on it. Event though the error message is shown by OnValidate, everything still works. It's just the error message.

[IMPORTANT] How can we reproduce the issue, step by step:
Please tell us how to reproduce your issue, STEP BY STEP, with one of our built in examples.
-> Set the script execution order to run NetworkIdentity after NetworkTransformReliable
-> In any script attempt to create a Game Object on runtime
-> Add component NetworkTransformReliable first
-> Then after add component NetworkIdentity

var networkTransform = splitRootObj.AddComponent<NetworkTransformReliable>();
var networkIdentity = splitRootObj.AddComponent<NetworkIdentity>();

-> Run the code
-> NetworkTransformReliable triggers OnValidate and before the NetworkIdentity's Awake method which results in NetworkTransformReliable not having netIdentity and the error message to be shown.

On the other hand, if I move AddComponent<NetworkIdentity>() to be called first, I end up with a null reference thrown on every frame as the NetworkIdentity's Awake is triggering before NetworkTransformReliable is registered in NetworkBehaviours.

var networkIdentity = splitRootObj.AddComponent<NetworkIdentity>();
var networkTransform = splitRootObj.AddComponent<NetworkTransformReliable>();

Any bug that can be reproduced, can be fixed.
If we can't reproduce it, we can't fix.

Expected behavior
No errors to be shown.

Desktop (please complete the following information):

  • OS: MacOS
  • Build target: Editor
  • Unity version: 2022.3.25f1
  • Mirror branch: main
@MrGadget1024
Copy link
Collaborator

Creating networked objects at runtime isn't supported, and we don't test for that or try to make that work, especially not with changing script execution order.

@ArturMoczulski
Copy link
Author

I don't understand what that means. What are the custom spawn handlers for then?

@MrGadget1024
Copy link
Collaborator

Object pooling, adding art from addressables at runtime, stuff like that. To spawn anything, client has to already have the prefab with the asset id that the server will send.

Bug report is not for discussion - join Discord for that.

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

No branches or pull requests

2 participants