Unity NetworkVariableでstringが使えないので FixedString32Bytesを利用してみる。

Unity

ArgumentException: Type System.String is not supported by NetworkVariable1. 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 and UserNetworkVariableSerialization.ReadValue, or if it's serializable by memcpy (contains no pointers), wrap it in ForceNetworkSerializeByMemcpy1.

という感じで
NetworkVariable<string>が使えなそうで

NetworkVariable | Unity Multiplayer Networking
Introduction

Unity fixed string types: 

FixedString32BytesFixedString64BytesFixedString128BytesFixedString512Bytes, and FixedString4096Bytes (which are serialized intelligently, only sending the used part across the network and adjusting the “length” of the string on the other side to fit the received data).

ということで NetworkVariable<FixedString32Bytes>に変更しました。

お気軽にコメントください!

スパム対応のためコメント認証に数日かかることがありますが、お気軽にコメントいただけると嬉しいです^^

コメント

タイトルとURLをコピーしました