Skip to content

feat: client network variables #1522

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

Closed

Conversation

mattwalsh-unity
Copy link
Contributor

@mattwalsh-unity mattwalsh-unity commented Dec 10, 2021

This PR would re-introduce client network variables. With this feature, client nv's can be used to allow clients to communicate input to the server as an alternative to RPCs, which can be useful especially until we introduce a proper input passing system.

MTT-1933

RFC required, deferring until I get some feedback

PR Checklist

  • Have you added a backport label (if needed)? For example, the type:backport-release-* label. After you backport the PR, the label changes to stat:backported-release-*.
  • Have you updated the changelog? Each package has a CHANGELOG.md file.
  • Have you updated or added the documentation for your PR? When you add a new feature, change a property name, or change the behavior of a feature, it's best practice to include related documentation changes in the same PR or a link to the documenation repo PR if this is a manual update.

Changelog

com.unity.netcode.gameobjects

  • Added: The package whose Changelog should be added to should be in the header. Delete the changelog section entirely if it's not needed.
  • Fixed: If you update multiple packages, create a new section with a new header for the other package.
  • Removed/Deprecated/Changed: Each bullet should be prefixed with Added, Fixed, Removed, Deprecated, or Changed to indicate where the entry should go.

Testing and Documentation

  • Includes integration tests.
  • Documentation changes & additions are necessary TODO


public override bool ShouldWrite(ulong clientId, bool isServer)
{
return m_IsDirty && !isServer && m_NetworkBehaviour.IsOwner;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A host wouldn't be able to write? If my character is client driven, I don't want different code for my host and my clients, both should be able to update their own characters.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, hosts should be able to write these, although I still yearn for the day when a "host" is just a client and a server running in the same process but each having their own version of each object.

@@ -67,6 +67,16 @@ public virtual bool ShouldWrite(ulong clientId, bool isServer)
return IsDirty() && isServer && CanClientRead(clientId);
}

/// <summary>
/// Gets Whether or not a specific client can read to the varaible
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Gets Whether or not a specific client can read to the varaible
/// Gets Whether or not a specific client can write to the variable

/// <summary>
/// A ClientNetworkVariable is special in that:
/// - only the owner of the variable can write to it
/// - not even the server can write to it
Copy link
Contributor

@SamuelBellomo SamuelBellomo Dec 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not even the server can write to it

I might have missed this with Owernship, but to me this would be covered by the IsOwner check no? IsOwner checks for
NetworkManager != null && OwnerClientId == NetworkManager.LocalClientId;
This would be false for the server?

/// A ClientNetworkVariable is special in that:
/// - only the owner of the variable can write to it
/// - not even the server can write to it
/// - it is not snapshotted
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the direction we were taking was for everything to be snapshotted. AFAIK the client can send snapshots to the server as well.

/// - it is not snapshotted
/// - it must be sent reliably
///
/// (This class may be removed in the future when integrated into NetworkVariable natively)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad I read this comment, I was gonna ask this question.


// Also, note this is not really very water-tight, if you are running as a host
// we cannot tell if a ClientNetworkVariable write is happening inside server-ish code
if (m_NetworkBehaviour && m_NetworkBehaviour.NetworkManager.IsServer)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be an opportunity to think about how we can decouple this from NetworkBehaviour and NetworkManager. We have NetworkBehaviour doing some initialization work on network variables, what about removing m_NetworkBehaviour and replacing it with internal void SetLocalPermissions(bool iCanRead, bool iCanWrite) and letting NetworkBehaviour tell NetworkVariable what its configuration should be, instead of having NetworkVariable poll for it the other way? This isn't going to change over the variable's lifetime and that would make network variables easier to unit test.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably also needs to pass OwnerClientId. Or possibly it could pass in delegates for "can write" and "can read" instead of booleans. That could give us the opportunity to give more advanced permission control to the user and let them write more complicated ownership and authority logic.

@mattwalsh-unity mattwalsh-unity requested review from becksebenius-unity and removed request for andrews-unity and SamuelBellomo January 13, 2022 00:13
@0xFA11
Copy link
Contributor

0xFA11 commented Mar 18, 2022

superseded by #1762

@0xFA11 0xFA11 closed this Mar 18, 2022
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

Successfully merging this pull request may close these issues.

4 participants