Title: Automatically invoke `NetworkVariable.OnValueChanged` when spawning · Issue #3186 · Unity-Technologies/com.unity.netcode.gameobjects · GitHub
Open Graph Title: Automatically invoke `NetworkVariable.OnValueChanged` when spawning · Issue #3186 · Unity-Technologies/com.unity.netcode.gameobjects
X Title: Automatically invoke `NetworkVariable.OnValueChanged` when spawning · Issue #3186 · Unity-Technologies/com.unity.netcode.gameobjects
Description: Feedback When load scene with in-scene placed NetworkObject or dynamically spawn NetworkObject, connected client would spawn the object and NetworkVariable value synced with the server. But the OnValueChanged is not called, even if the v...
Open Graph Description: Feedback When load scene with in-scene placed NetworkObject or dynamically spawn NetworkObject, connected client would spawn the object and NetworkVariable value synced with the server. But the OnV...
X Description: Feedback When load scene with in-scene placed NetworkObject or dynamically spawn NetworkObject, connected client would spawn the object and NetworkVariable value synced with the server. But the OnV...
Opengraph URL: https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3186
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Automatically invoke `NetworkVariable.OnValueChanged` when spawning","articleBody":"**Feedback**\nWhen load scene with in-scene placed `NetworkObject` or dynamically spawn `NetworkObject`, connected client would spawn the object and `NetworkVariable` value synced with the server. But the `OnValueChanged` is not called, even if the value has been synced with the value of server, and is different from the default value that has been set in `NetworkBehaviour`. The current behavior of skipping `OnValueChanged` when spawning also doesn't depend on where the `OnValueChanged` has been registered, in `OnNetworkSpawn` , `OnNetworkPreSpawn` or even in `Awake`.\n\nThis caused a lot of problems, because `NetworkVariable` may be a bool that enable/disable a renderer, or set a shader field through `OnValueChanged`. Skipping `OnValueChanged` would make render frame inconsistent with what's intended. This is specially annoying when late-join client starts to spawn all `NetworkObject`, without `OnValueChanged` the game states would drastically different from server. The problem also shows up when a previously `NetworkHide` object become visible again and client respwan the object but with inconsistent states from server.\n\n**Suggested Changes**\nWhen spawning, all `NetworkVariable` should be synchronized, and corresponding `OnValueChanged` should all get called, because clients are supposed to keep the same states as server. The server has likely changed the value of `NetworkVariable` and have already called the `OnValueChanged` on server side, so when spawning happens, client need to not only sync all values of `NetworkVariable`, but also call all `OnValueChanged` to keep the same states as server.\n\nAn intuitive way is to register `OnValueChanged` in `OnNetworkPreSpawn`, so that during subsequent spawning any valid callbacks registered will get called.\n","author":{"url":"https://github.com/babaq","@type":"Person","name":"babaq"},"datePublished":"2024-12-30T01:54:12Z","url":"https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/3186"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ba44a026-0115-2026-fd78-1d5aacd4237a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AC3C:370586:1EE801:2B2956:6B00575A |
| html-safe-nonce | 5b4271c112b8cd16a5dfd5e13d015947e3cfa5cb1c751f20d994378e6bf0e1a3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzNDOjM3MDU4NjoxRUU4MDE6MkIyOTU2OjZCMDA1NzVBIiwidmlzaXRvcl9pZCI6IjUzODkzNDg0NjI1ODIwNjA4OTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3b77188bc5c19de19d0653f3b9646afaaf20c91cf326a1d637dbf8095c4ed603 |
| hovercard-subject-tag | issue:2762547316 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/Unity-Technologies/com.unity.netcode.gameobjects/3186/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4586f3f4511d29ae1511c99b9cb34c141754b8f6ee9ddd0cffd68348a7835a6e/Unity-Technologies/com.unity.netcode.gameobjects/issues/3186 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4586f3f4511d29ae1511c99b9cb34c141754b8f6ee9ddd0cffd68348a7835a6e/Unity-Technologies/com.unity.netcode.gameobjects/issues/3186 |
| og:image:alt | Feedback When load scene with in-scene placed NetworkObject or dynamically spawn NetworkObject, connected client would spawn the object and NetworkVariable value synced with the server. But the OnV... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | babaq |
| hostname | github.com |
| expected-hostname | github.com |
| None | f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb |
| turbo-cache-control | no-preview |
| go-import | github.com/Unity-Technologies/com.unity.netcode.gameobjects git https://github.com/Unity-Technologies/com.unity.netcode.gameobjects.git |
| octolytics-dimension-user_id | 426196 |
| octolytics-dimension-user_login | Unity-Technologies |
| octolytics-dimension-repository_id | 116385203 |
| octolytics-dimension-repository_nwo | Unity-Technologies/com.unity.netcode.gameobjects |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 116385203 |
| octolytics-dimension-repository_network_root_nwo | Unity-Technologies/com.unity.netcode.gameobjects |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 26e00df917aba0f128135dc073ea0c5e33a70d40 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width