• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Zardoz7 · Feb 15 at 05:09 AM · networkingtransport

String from input field to datastream

Hi,

I'm very new to Unity and I'm trying to learn how to work with the transport layer but am finding the documentation difficult to follow. Here are some of the details:

  1. Unity 2021.2.8f1

  2. Unity Transport 1.0.0-pre.12

  3. jobs 0.11.0-preview.6

I've found a really helpful tutorial however, it was created 11 months ago and I believe there have been a few versions of Transport and Jobs released since then. That being said:

The Setup: I have an Input Field used to enter text. The text should be passed to the server and displayed in the log.

The Code: ChatMessageTest.cs using TMPro; using UnityEngine; using Unity.Collections;

 public class ChatMessageTest : MonoBehaviour
 {
     [SerializeField] private TMP_InputField chatInput;
             
     public void OnSubmitClick()
     {
         Net_ChatMessage msg = new Net_ChatMessage(chatInput.text);
         FindObjectOfType<BaseClient>().SendToServer(msg);
     }
 }

Net_ChatMessage using Unity.Collections; using Unity.Networking.Transport; using UnityEngine;

 public class Net_ChatMessage : NetMessage
 {
     // 0 - 8 first bits are reserved for the OP Code
     // 8 - 128 String message
 
     public FixedString128Bytes ChatMessage { set; get; }
 
     public Net_ChatMessage()
     {
         Code = OpCode.CHAT_MESSAGE;
     }
 
     public Net_ChatMessage(DataStreamReader reader)
     {
         Code = OpCode.CHAT_MESSAGE;
         Deserialize(reader);
     }
 
     public override void Serialize(ref DataStreamWriter writer)
     {
         writer.WriteByte((byte)Code);
         writer.WriteFixedString128(ChatMessage);
     }
 
     public override void Deserialize(DataStreamReader reader)
     {
         // The first byte is already handled by the 'OnData' function in base server.
         ChatMessage = reader.ReadFixedString128();
     }
 
     public override void ReceivedOnServer()
     {
         Debug.Log("SERVER::" + ChatMessage);
         //base.ReceivedOnServer();
     }
 
     public override void ReceivedOnClient()
     {
         Debug.Log("CLIENT::" + ChatMessage);
         //base.ReceivedOnServer();
     }
 }

The error message:

CS1503 Argument 1: cannot convert from 'string' to Unity.Networking.Transport.DataStreamReader'

I have that funny feeling that I'm missing something simply. I just can't seem to figure out how convert it. It's been a long day. I'm open to any help on this and any suggestions you may have for documentation/tutorials/sources for more information

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

228 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

AnyIpv4 and LoopbackIpv4 2 Answers

What is the most efficient way to host multiple games on different ports? 1 Answer

How to sync position using new unity transport? 1 Answer

Warning: not all old messages was acknowledged 1 Answer

TransportLayer API sending message from one Client to multiple "Servers" 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges