Skip to content

feat: Adding support for netsim to be able to work with Tools adapter #2184

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

Merged
merged 17 commits into from
Sep 23, 2022

Conversation

Rosme
Copy link
Contributor

@Rosme Rosme commented Sep 8, 2022

This adds an internal callback to tell the tools adapter that the transport is initialized and ready so we can act on it and be aware of it.

Testing and Documentation

  • No tests have been added.

@Rosme Rosme requested a review from a team September 8, 2022 20:18
@Rosme Rosme requested review from 0xFA11 and a team as code owners September 8, 2022 20:18
@@ -346,6 +346,10 @@ private struct PacketLossCache
public float PacketLoss;
};

internal static event Action<UnityTransport> TransportInitialized;
internal static event Action<UnityTransport> TransportDisposed;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should a reference to the Transport be included in the disposed message? Is it still valid at that point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, since we are using the Instance ID to track the adapter.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you expand on what the value is of tracking dispose instead of shutdown? Does this need to be an event or can you use a weak reference?

To expand on Ian's concern and my other comment about internals vs public, at the point you have this being invoked the object is essentially "off limits" to other objects as far as best practices go - regardless of how this may be used right now this feels dangerous and dependent on tribal knowledge about the control flow. If all you need is the ID, why not pass that as the event parameter instead of the entire (mostly disposed) object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's more to it. We are using the whole UnityTransport to access the Network Driver. Arguably, we could provide the Instance ID and the Network Driver only as arguments. I am not against this change. As for the Disposed, we definitely only need the Instance ID and I can change it in the same manner if you'd prefer that.

@Rosme Rosme requested a review from JesseOlmer September 12, 2022 18:09
@@ -346,6 +346,10 @@ private struct PacketLossCache
public float PacketLoss;
};

internal static event Action<UnityTransport> TransportInitialized;
internal static event Action<UnityTransport> TransportDisposed;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you expand on what the value is of tracking dispose instead of shutdown? Does this need to be an event or can you use a weak reference?

To expand on Ian's concern and my other comment about internals vs public, at the point you have this being invoked the object is essentially "off limits" to other objects as far as best practices go - regardless of how this may be used right now this feels dangerous and dependent on tribal knowledge about the control flow. If all you need is the ID, why not pass that as the event parameter instead of the entire (mostly disposed) object?


#if UNITY_EDITOR || DEVELOPMENT_BUILD
#if UNITY_EDITOR || DEVELOPMENT_BUILD || UNITY_MP_TOOLS_NETSIM_IMPLEMENTATION_ENABLED
Copy link
Contributor

Choose a reason for hiding this comment

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

Is UNITY_EDITOR || DEVELOPMENT_BUILD here because the NETSIM define is 2.0 only? Can't we simplify these cases in the first define?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to maintain the existing Debug Simulator as well if the Tools are not present. But since the Network Simulator can also be included in Release builds if the user wished so, we need all three.

JS Fauteux and others added 2 commits September 14, 2022 10:27
Co-authored-by: Jesse Olmer <jesseo@unity3d.com>
@Rosme
Copy link
Contributor Author

Rosme commented Sep 14, 2022

@JesseOlmer @becksebenius-unity Per our alignment, I've updated the PR to remove Debug Simulator if we are using UTP 2. I split the stuff to avoid a mixtures of weird ifdef all over the place.

This also updating the callback for the adapter to avoid passing the whole Unity Transport.

@simon-lemay-unity
Copy link
Contributor

Per our alignment, I've updated the PR to remove Debug Simulator if we are using UTP 2. I split the stuff to avoid a mixtures of weird ifdef all over the place.

I understand there's already alignment on this at a higher level than me, but we're okay introducing a breaking API change if someone happens to have UTP 2.0 installed?

@Rosme
Copy link
Contributor Author

Rosme commented Sep 14, 2022

Per our alignment, I've updated the PR to remove Debug Simulator if we are using UTP 2. I split the stuff to avoid a mixtures of weird ifdef all over the place.

I understand there's already alignment on this at a higher level than me, but we're okay introducing a breaking API change if someone happens to have UTP 2.0 installed?

As we see it, UTP 2 is already considered a breaking change. Technically, you need to get UTP2 to have this breaking change. If you just get the latest of NGO, it's not a breaking change. If you are willing to go to UTP2, you are accepting that change.

@simon-lemay-unity
Copy link
Contributor

As we see it, UTP 2 is already considered a breaking change. Technically, you need to get UTP2 to have this breaking change. If you just get the latest of NGO, it's not a breaking change. If you are willing to go to UTP2, you are accepting that change.

I'm not sure I understand what you mean by UTP 2.0 being a breaking change. With the recent changes that landed, someone installing UTP 2.0 will get something that still works without having to modify their code. All breaking API changes introduced by UTP 2.0 are handled by NGO through version defines. But with the proposed changes here, someone could install UTP 2.0 and get a non-compiling project without any indication as to what happened.

I understand (and support) the rationale of not wanting to support the existing debug simulator if UTP 2.0 is installed. That's fine. Users with UTP 2.0 should install the tools package to get the new and improved network simulator. But straight out removing the API gives them absolutely no indication that this is what is expected of them. At least change the implementation to throw an exception or log an error or something so that users won't end up with a non-compiling application and no idea of how to proceed. Or at the very least add an entry to the changelog indicating how users are expected to handle this.

@becksebenius-unity
Copy link
Contributor

As we see it, UTP 2 is already considered a breaking change. Technically, you need to get UTP2 to have this breaking change. If you just get the latest of NGO, it's not a breaking change. If you are willing to go to UTP2, you are accepting that change.

I'm not sure I understand what you mean by UTP 2.0 being a breaking change. With the recent changes that landed, someone installing UTP 2.0 will get something that still works without having to modify their code. All breaking API changes introduced by UTP 2.0 are handled by NGO through version defines. But with the proposed changes here, someone could install UTP 2.0 and get a non-compiling project without any indication as to what happened.

I understand (and support) the rationale of not wanting to support the existing debug simulator if UTP 2.0 is installed. That's fine. Users with UTP 2.0 should install the tools package to get the new and improved network simulator. But straight out removing the API gives them absolutely no indication that this is what is expected of them. At least change the implementation to throw an exception or log an error or something so that users won't end up with a non-compiling application and no idea of how to proceed. Or at the very least add an entry to the changelog indicating how users are expected to handle this.

An alternative to this would to be use [HideInInspector] to remove it from the inspector UI, and then use [Obsolete] tag to indicate to users that the API should not be used if they have UTP2.0 installed. I believe this would satisfy semantic versioning and give better feedback to users if they're relying on that API.

@Rosme
Copy link
Contributor Author

Rosme commented Sep 14, 2022

As we see it, UTP 2 is already considered a breaking change. Technically, you need to get UTP2 to have this breaking change. If you just get the latest of NGO, it's not a breaking change. If you are willing to go to UTP2, you are accepting that change.

I'm not sure I understand what you mean by UTP 2.0 being a breaking change. With the recent changes that landed, someone installing UTP 2.0 will get something that still works without having to modify their code. All breaking API changes introduced by UTP 2.0 are handled by NGO through version defines. But with the proposed changes here, someone could install UTP 2.0 and get a non-compiling project without any indication as to what happened.
I understand (and support) the rationale of not wanting to support the existing debug simulator if UTP 2.0 is installed. That's fine. Users with UTP 2.0 should install the tools package to get the new and improved network simulator. But straight out removing the API gives them absolutely no indication that this is what is expected of them. At least change the implementation to throw an exception or log an error or something so that users won't end up with a non-compiling application and no idea of how to proceed. Or at the very least add an entry to the changelog indicating how users are expected to handle this.

An alternative to this would to be use [HideInInspector] to remove it from the inspector UI, and then use [Obsolete] tag to indicate to users that the API should not be used if they have UTP2.0 installed. I believe this would satisfy semantic versioning and give better feedback to users if they're relying on that API.

I believe the issue that @JesseOlmer was pointing out though is that we still have an existing API that doesn't do anything in that situation, though the [Obsolete] part could indicate that.

@DenninDalke DenninDalke force-pushed the feature/tools-netsim-support branch from 752ddd7 to 838485b Compare September 20, 2022 21:33
Comment on lines +372 to +373
internal static event Action<int, NetworkDriver> TransportInitialized;
internal static event Action<int> TransportDisposed;
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason we can't make these public and then remove the internalsvisibleto? I'd love to get rid of "hidden" public apis.

@DenninDalke DenninDalke force-pushed the feature/tools-netsim-support branch from 5b05dda to 61e04e5 Compare September 22, 2022 22:21
@DenninDalke DenninDalke removed the request for review from becksebenius-unity September 22, 2022 23:19
@DenninDalke DenninDalke enabled auto-merge (squash) September 23, 2022 02:13
@DenninDalke DenninDalke merged commit 5989836 into develop Sep 23, 2022
@DenninDalke DenninDalke deleted the feature/tools-netsim-support branch September 23, 2022 02:13
jakobbbb pushed a commit to GooseGirlGames/com.unity.netcode.gameobjects that referenced this pull request Feb 22, 2023
…Unity-Technologies#2184)

* Adding support for netsim to be able to work with Tools adapter
* Setting up Simulator Pipeline stage if NetSim is available
* Deprecate DebugSimulator when using UTP2

Co-authored-by: Jesse Olmer <jesseo@unity3d.com>
Co-authored-by: DenninDalke <dennindalke@gmail.com>
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.

7 participants