Skip to content
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

Add built-in serialization for UnityEngine.Pose #2675

Open
PitouGames opened this issue Aug 24, 2023 · 0 comments · May be fixed by #2677
Open

Add built-in serialization for UnityEngine.Pose #2675

PitouGames opened this issue Aug 24, 2023 · 0 comments · May be fixed by #2677
Labels
stat:awaiting triage Status - Awaiting triage from the Netcode team. type:feature New feature, request or improvement

Comments

@PitouGames
Copy link
Contributor

PitouGames commented Aug 24, 2023

Is your feature request related to a problem? Please describe.

Unity provide a primitive struct called Pose, which is a composition of a Vector3 and a Quaternion. This type is not very known, but very usefull, for instance in a single list of waypoints that also need to store their rotation.

This type is not listed in the documentation: https://docs-multiplayer.unity3d.com/netcode/current/advanced-topics/serialization/unity-primitives/, and doesn't work if used in an Rpc or NetworkVariable.

[ServerRpc()]
private void TestServerRpc(Pose p)
{
    Debug.Log(p);
}
Assets\Scripts\Test.cs(32,13): error  - TestServerRpc - Don't know how to deserialize UnityEngine.Pose. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace UnityEngine.Pose with ForceNetworkSerializeByMemcpy`1<UnityEngine.Pose>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out UnityEngine.Pose) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in UnityEngine.Pose) to define serialization for this type.
private NetworkList<Pose> poseList = new NetworkList<Pose>();

private void AddAnItem() {
    poseList.Add(new Pose(transform.position, transform.rotation));
}
ArgumentException: Type UnityEngine.Pose is not supported by NetworkVariable`1. If this is a type you can change, then either implement INetworkSerializable or mark it as serializable by memcpy by adding INetworkSerializeByMemcpy to its interface list. If not, assign serialization code to UserNetworkVariableSerialization.WriteValue, UserNetworkVariableSerialization.ReadValue, and UserNetworkVariableSerialization.DuplicateValue, or if it's serializable by memcpy (contains no pointers), wrap it in ForceNetworkSerializeByMemcpy`1.

Describe the solution you'd like
Add a default serializer for UnityEngine.Pose.

Describe alternatives you've considered
Today, users have to implement their own serializer or send Vector3 and Quaterion separately.

@PitouGames PitouGames added stat:awaiting triage Status - Awaiting triage from the Netcode team. type:feature New feature, request or improvement labels Aug 24, 2023
PitouGames added a commit to PitouGames/com.unity.netcode.gameobjects that referenced this issue Aug 25, 2023
PitouGames added a commit to PitouGames/com.unity.netcode.gameobjects that referenced this issue Aug 31, 2023
PitouGames added a commit to PitouGames/com.unity.netcode.gameobjects that referenced this issue Nov 13, 2023
PitouGames added a commit to PitouGames/com.unity.netcode.gameobjects that referenced this issue May 1, 2024
PitouGames added a commit to PitouGames/com.unity.netcode.gameobjects that referenced this issue May 1, 2024
PitouGames added a commit to PitouGames/com.unity.netcode.gameobjects that referenced this issue May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:awaiting triage Status - Awaiting triage from the Netcode team. type:feature New feature, request or improvement
Projects
None yet
1 participant