Skip to content

Add NetworkColliderBase GetLayers/SetLayers - #1093

Open
jimdroberts wants to merge 1 commit into
FirstGearGames:mainfrom
jimdroberts:feat/networkcollider-layers-accessor
Open

jimdroberts wants to merge 1 commit into
FirstGearGames:mainfrom
jimdroberts:feat/networkcollider-layers-accessor

Conversation

@jimdroberts

Copy link
Copy Markdown
Contributor

Problem

NetworkTrigger, NetworkCollision and NetworkTrigger2D are sealed, and their Layers mask is a protected field. There is no way to read or set the query layers from code. A component added with AddComponent, or one whose required layers are only known at runtime, is stuck with the serialized value.

When the mask is wrong, nothing reports it. If Layers is nothing, the mask is derived from the collision-matrix row of the component's own GameObject layer. If Layers is authored without a needed bit, those objects are simply never overlapped. The tooltip only says "This is used when value is not nothing", so the fallback is not discoverable.

Cause

Runtime/Generated/Component/Prediction/NetworkColliderBase.cs on main:

  • L35-38: protected LayerMask Layers has no public accessor. The concrete components are sealed, so it cannot be reached by subclassing either.
  • L139-152: TryPrepareColliderCheck uses Layers when it is not nothing. Otherwise it uses Layers.GetInteractableLayersValue(gameObject.layer), cached by _lastGameObjectLayer.

Fix

  • Add GetLayers() / SetLayers(LayerMask), following the Get/Set accessor style used elsewhere (for example NetworkTransform.SetSendToOwner). SetLayers resets _lastGameObjectLayer. Without that, switching from an explicit mask back to nothing would keep using the explicit mask: InteractableLayers was overwritten, and the layer cache still matched the GameObject's layer. The new value takes effect on the next check.
  • The Layers summary and tooltip now describe the fallback when the value is nothing.

No warning is added for Layers == 0. It is a documented, working default, and warning on it would flag every correctly configured project.

Layers is a protected field and the concrete NetworkTrigger/NetworkCollision
components are sealed, so code could neither read nor set the query mask. Add
GetLayers/SetLayers. SetLayers resets the cached GameObject layer so that going
back to Nothing derives the mask from the collision matrix again. The Layers
tooltip now documents that fallback.
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.

1 participant