-
Notifications
You must be signed in to change notification settings - Fork 447
feat: Allow to pass custom data on Spawn calls #3419
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
Conversation
Thank you for your contribution! At this time, we would rather avoid adding parameters to the Could an approach like the |
thanks for the feedback! i will open an issue regarding my use case there is currently a forum post on unity i made for it, which is this I might copiy this into an issue to see if there is a pleasing solution here is the issue i created Also would it help if it were a new method instead of adding a parameter to the original method? Perhaps I could explore introducing a kind of spawn builder system where the Spawn() methods remain untouched, but external data can be attached through a chainable builder pattern. This would preserve the current API while allowing advanced usage patterns without impacting existing workflows or causing order issues Another idea I’d like to experiment with is decoupling the INetworkPrefabInstanceHandler from prefabs entirely, so it acts more like a general-purpose "Spawner" rather than being strictly tied to prefab references |
In order to avoid feature creeping the core spawn methods, I’d propose a change that keeps those untouched. so the api usage would be: NetworkManager.SpawnManager.SetCustomSpawnData(myBasePrefabToPointTheHandler, customData);
NetworkManager.SpawnManager.InstantiateAndSpawn(myBasePrefabToPointTheHandler); And to improve support for inScenePlaced objects, this customSpawnData could optionally be embedded into the Does that sound like a better fit? If this approach sounds more aligned with the direction you'd prefer, I’d be happy to proceed with the necessary changes to make it viable |
Hey, just a quick PR related note that you should probably rebase to target |
Thanks for letting me know! I've just rebased the PR to target |
Hi @Extrys, Thank you for submitting your proposed changes. We always love community contributions...of course we might not always have enough time to review everything. Unfortunately, the change you are proposing is most likely not going to be approved for several reasons. The primary reason is that while your PR submission appears to cover the initial spawning of the NetworkObject it does not handle synchronizing late joining clients. Example:
Your implementation would only work under the condition of:
I had posted a reply to your forum post here asking a bit more about why the ID assignment and more information as to why you needed this information during the instantiation as opposed to just using OnSynchronize as I had outlined. If you could provide that information to me I might be able to assist and/or you could submit a bug report within the editor that includes your project and post that ticket here so I could look over your project and possibly provide some guidance on how you could achieve your goals without this type of modification... in the end the modification you are proposing would require storing the customData information in each instance permanently as well as change the existing public facing API (which both will be very difficult to get alignment for this without understanding your project/approach and determining if there is no other possible way to accomplish what you are trying to accomplish using the existing API). |
Thanks a lot for the detailed breakdown and for taking the time to investigate the PR so thoroughly. I really appreciate it. Regarding the issue with late-joining clients: I'll review your reply on the forum now. If we can’t find a clean solution through the existing API, I’d be happy to explore a new version of the proposal. one that handles:
Instead, the approach would rely on internal extensions and optional hooks, keeping the default flow intact for existing users. NetworkManager.SpawnManager.SetCustomSpawnData(myBasePrefabToPointTheHandler, customData);
NetworkManager.SpawnManager.InstantiateAndSpawn(myBasePrefabToPointTheHandler); Let me know if that sounds worth exploring, and thanks again for your time and feedback! ❤️ Now, heading to the forum! |
Closing this PR in favor of a new, much cleaner and more aligned solution.
Follow-up PR: #3430 |
This PR introduces support for passing custom spawn data from the server to clients during the spawn process of a
NetworkObject
.This enables deterministic instantiation or contextual setup on the client without relying on RPCs or external sync steps.
Doesn't break or invalidate existing user code
the feature is fully optional and designed via an extension interface to preserve full backward compatibility.
Changelog
INetworkCustomSpawnDataReceiver
interface to allow reading custom spawn data on the client side.CreateObjectMessage
now includes optional CustomSpawnData handling.Testing and Documentation
Deprecated API
Backport
Implementation example