Skip to content

Commit 43d7379

Browse files
Merge branch 'develop-2.0.0' into fix/networktransform-autoswitchspace-forcing-updates-localspace
2 parents 2e1c329 + 5f16181 commit 43d7379

File tree

8 files changed

+465
-413
lines changed

8 files changed

+465
-413
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1212

1313
- Added NetworkRigidbody documentation section. (#3664)
1414
- Clicking on the Help icon in the inspector will now redirect to the relevant documentation. (#3663)
15+
- Added a `Set` function onto `NetworkList` that takes an optional parameter that forces an update to be processed even if the current value is equal to the previous value. (#3690)
1516

1617
### Changed
1718

com.unity.netcode.gameobjects/Documentation~/samples.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ Use the samples in this section to learn how to use Netcode for GameObjects in y
44

55
| **Topic** | **Description** |
66
| :------------------------------ | :------------------------------- |
7-
| **[NetworkBehaviour](components/core/networkbehaviour.md)** | [NetworkBehaviour](https://docs.unity3d.com/Packages/com.unity.netcode.gameobjects@latest?subfolder=/api/Unity.Netcode.NetworkBehaviour.html) is an abstract class that derives from [MonoBehaviour](https://docs.unity3d.com/ScriptReference/MonoBehaviour.html) and is primarily used to create unique netcode or game logic. To replicate any netcode-aware properties or send and receive RPCs, a [GameObject](https://docs.unity3d.com/Manual/GameObjects.html) must have a [NetworkObject](components/core/networkobject.md) component and at least one NetworkBehaviour component. |
8-
| **[Synchronize](components/core/networkbehaviour-synchronize.md)** | You can use NetworkBehaviours to synchronize settings before, during, and after spawning NetworkObjects. |
7+
| **[Bossroom](samples/bossroom/bossroom-landing.md)** | The Boss Room sample is a multiplayer game that demonstrates how to use Netcode for GameObjects to create a networked game. It provides a complete example of how to implement various features such as player movement, combat, and game state management in a multiplayer environment. |

com.unity.netcode.gameobjects/Documentation~/samples/bitesize/bitesize-spaceshooter.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ The [2D Space Shooter Project](https://github.com/Unity-Technologies/com.unity.m
44

55
## Server Authoritative Physics Movement
66

7-
The movement in 2DSpaceShooter is physics based. The player object is a dynamic rigidbody and can collide with other players or asteroids. Physics in multiplayer games can be hard to get right. For simplicity, 2DSpaceShooter runs all movement and physics just on the server-side.
7+
The movement in 2DSpaceShooter is physics based. The player object is a [dynamic Rigidbody](https://docs.unity3d.com/Documentation/Manual/2d-physics/rigidbody/body-types/dynamic/dynamic-body-type-reference.html) and can collide with other players or asteroids. Physics in multiplayer games can be hard to get right. For simplicity, 2DSpaceShooter runs all movement and physics just on the server-side.
88

99
The client sends inputs in the form of RPCs to the server. The server then uses those inputs to adjust the throttle and turn values of the player.
1010

1111
This method of running physics makes sure that there are no desyncs or other physics issues between the client and server, but it introduces more latency.
1212

1313
## Player Health
1414

15-
2DSpaceShooter uses `NetworkVariable`s to track the players health and energy. Both variables are server authoritative, only the host or server can make changes to them. The client draws the player's health bar simply by accessing the value of the `NetworkVariable`.
15+
2DSpaceShooter uses [NetworkVariables](../../basics/networkvariable.md) to track the players health and energy. Both variables are server authoritative, only the host or server can make changes to them. The client draws the player's health bar simply by accessing the value of the `NetworkVariable`.
1616

1717
For example:
1818

@@ -34,9 +34,9 @@ https://github.com/Unity-Technologies/com.unity.multiplayer.samples.bitesize/blo
3434

3535
## NetworkObject Pooling
3636

37-
The `2DSpaceShooter` object creates many objects dynamically at runtime including bullets, asteroids, and pickups. 2DSpaceShooter uses object pooling to avoid performance issues of instantiating and destroying Unity Objects all the time and creating allocations in the process.
37+
The `2DSpaceShooter` object creates many objects dynamically at runtime including bullets, asteroids, and pickups. 2DSpaceShooter uses [object pooling](../../advanced-topics/object-pooling.md) to avoid performance issues of instantiating and destroying Unity Objects all the time and creating allocations in the process.
3838

39-
2DSpaceShooter uses the NetworkObjectPool script, which can be found in the Community Contributions Repository.
39+
2DSpaceShooter uses the NetworkObjectPool script, which can be found in the [Community Contributions Repository](https://github.com/Unity-Technologies/multiplayer-community-contributions).
4040

4141
![pool img](../../images/bitesize/invader-networkobjectpool.png)
4242

com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Runtime.CompilerServices;
34
using Unity.Collections;
45

56
namespace Unity.Netcode
@@ -597,45 +598,60 @@ public void RemoveAt(int index)
597598
}
598599

599600
/// <summary>
600-
/// Gets or sets the element at the specified index in the <see cref="NetworkList{T}"/>.
601+
/// Sets the element at the specified index in the <see cref="NetworkList{T}"/>.
601602
/// </summary>
602603
/// <remarks>
603-
/// This method checks for write permissions before setting the value.
604+
/// This method checks for write permissions and equality before setting and updating the value.
604605
/// </remarks>
605-
/// <param name="index">The zero-based index of the element to get or set.</param>
606-
/// <value>The element at the specified index.</value>
607-
public T this[int index]
606+
/// <param name="index">The zero-based index of the element to set.</param>
607+
/// <param name="value">The new value to set at the given index</param>
608+
/// <param name="forceUpdate">
609+
/// Ignores the equality check when setting the value.
610+
/// This option can send unnecessary updates to all clients when the value hasn't changed.
611+
/// </param>
612+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
613+
public void Set(int index, T value, bool forceUpdate = false)
608614
{
609-
get => m_List[index];
610-
set
615+
// check write permissions
616+
if (CannotWrite)
611617
{
612-
// check write permissions
613-
if (CannotWrite)
614-
{
615-
LogWritePermissionError();
616-
return;
617-
}
618+
LogWritePermissionError();
619+
return;
620+
}
618621

619-
var previousValue = m_List[index];
622+
var previousValue = m_List[index];
620623

621-
// Only trigger an event if the value has changed
622-
if (NetworkVariableSerialization<T>.AreEqual(ref previousValue, ref value))
623-
{
624-
return;
625-
}
624+
// Only trigger an event if the value has changed
625+
if (!forceUpdate && NetworkVariableSerialization<T>.AreEqual(ref previousValue, ref value))
626+
{
627+
return;
628+
}
626629

627-
m_List[index] = value;
630+
m_List[index] = value;
628631

629-
var listEvent = new NetworkListEvent<T>()
630-
{
631-
Type = NetworkListEvent<T>.EventType.Value,
632-
Index = index,
633-
Value = value,
634-
PreviousValue = previousValue
635-
};
632+
var listEvent = new NetworkListEvent<T>()
633+
{
634+
Type = NetworkListEvent<T>.EventType.Value,
635+
Index = index,
636+
Value = value,
637+
PreviousValue = previousValue
638+
};
636639

637-
HandleAddListEvent(listEvent);
638-
}
640+
HandleAddListEvent(listEvent);
641+
}
642+
643+
/// <summary>
644+
/// Gets or sets the element at the specified index in the <see cref="NetworkList{T}"/>.
645+
/// </summary>
646+
/// <remarks>
647+
/// This method checks for write permissions before setting the value.
648+
/// </remarks>
649+
/// <param name="index">The zero-based index of the element to get or set.</param>
650+
/// <value>The element at the specified index.</value>
651+
public T this[int index]
652+
{
653+
get => m_List[index];
654+
set => Set(index, value);
639655
}
640656

641657
/// <summary>

0 commit comments

Comments
 (0)