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.13k stars 433 forks source link

Client-side Prediction with Reconciliation - I have an implementation - pull request? #2413

Open pjuke opened 1 year ago

pjuke commented 1 year ago

Is your feature request related to a problem? Please describe. As the official roadmap says;

Instead of always waiting for the authority of the network to provide your client players a new position or state change, this feature would allow clients to apply player inputs immediately in attempt to predict what changes will happen in the near future.

Describe the solution you'd like Me and my team are currently working on a new multiplayer game where we had to implement this missing feature. The current solution is a relatively small modification to the existing NetworkTransform class, mostly adding new methods and logic to handle the prediction and reconciliation.

Our solution fully supports the common "Replay and Rewind" strategy, is ticking at a constant rate (the network tick rate actually) and is tolerant to jitters and package drops (partly from the internal interpolators already implemented).

It also supports making Unreliable RPC's to the server to make it even more suitable if you are making a more intense FPS game or what not.

Describe alternatives you've considered We initially tried an inheritance approach, inheriting from NetworkTransform, thus needing no modifications at all. But due to some access restrictions it was not fully suitable. However, it is possible to create an inherited version, but that requires to change some private members to protected and such (accessing the interpolators and ReplicatedNetworkState for example).

Additional context I guess our question is really if this would be something you'd be interested in to take a look at and maybe integrate it officially? Regarding modifying the NetworkTransform by adding new logic, or going for the inheritance approach works either way - it's up to you what you'd prefer.

If you are interested, how do we share these modifications and code the best way? Do we make a pull request and we can take it from there or how would you like to go by? :)

Thank you in advance! Cheers!

NoelStephensUnity commented 1 year ago

@pjuke Hi Eric! We are always open to community contributions. There is one pending draft PR for some NetworkTransform updates, so it might be better to base your changes off of that branch before submitting the PR or wait for that PR to land into develop.

However, if you are willing to share with the NGO community then we are definitely open to community contributions!
All PRs submitted are reviewed by NGO team members, so there is no guarantee the PR will be merged/accepted.

pjuke commented 1 year ago

@NoelStephensUnity Hi Noel! Nice to hear! I'd love to share our work and also receive feedback/contributions.

I will integrate it into that feature branch instead, that seem more appropriate. Once done, is it better then to make a PR for you to look at, or post the code here in this thread for feedback before PR?

Thank you in advance!

lpmaurice commented 1 year ago

Hi @pjuke, If you already have working code, then a PR should be the easiest thing both for you and for us.

andreyshade commented 1 year ago

Hi @pjuke. Great news! Could you share your solution? Thanks in advance!

pjuke commented 1 year ago

Hi @pjuke, If you already have working code, then a PR should be the easiest thing both for you and for us. Hi @pjuke. Great news! Could you share your solution? Thanks in advance!

Great! We are currently in the midst of some refactoring for the game and will make a PR with the suggested solution in the near future. :)

westonleavitt commented 1 year ago

Hey there! @pjuke Any chance you would be willing to share that implementation?