Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 Martinomat · Jun 16, 2016 at 12:12 PM · c#serialization

MessageBase with custom member variable

I'm having trouble with a custom message base.

It's very simple:

 public class CustomUpdate : MessageBase {
     public CustomClass object;
 }

CustomClass looks as follows:

 public class CustomClass {
     public string id;
     public List<int> clients;
 }

However, I'm getting multiple errors here. I'm quite sure it has something to do with the List<int>, cause I don't get any errors, when I uncomment that property.

The error messages are

UNetWeaver error: GenerateSerialization for CustomUpdate unknown type [CustomClass/CustomClass]. UNet [MessageBase] member variables must be basic types.

and

UNetWeaver error: WriteReadFunc for clients [System.Collections.Generic.List '1<System.Int32>/System.Collections.Generic.List'1<System.Int32>]. Cannot have generic parameters.

Any idea how to fix this error?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AntonQvarfordt · Apr 17, 2017 at 06:57 AM

@Martinomat This isn't really my area (I'm working on learning it atm aswell) so I can't tell you how to solve the problem, but I can tell you why it doesn't work..

MessageBase/Reader/Writer doesn't support lists. To see what it supports check out the public functions here: https://docs.unity3d.com/ScriptReference/Networking.NetworkReader.html

You can probably turn a list or at least an array into Bytes or something like that and pack/unpack that conversion in Write/Read. Maybe that gives you an idea of what to search for, at least.

EDIT: I ended up needing the same solution you needed so I'll post my findings here. I'm posting two methods, one turns a list of ints into a string, the other turns a string into a list of ints. So replace the List clients with a string clients and use these functions to convert to and from.

 public string WriteToString(List<int> intList)
 {
     StringBuilder sb = new StringBuilder("");
     foreach (int i in intList)
     {
         sb.Append(i + "_");
     }
     return = sb.ToString();
 }

 public List<int> ReadToIntList(string str)
 {
     var returnValue = new List<int>();
     var splitIntList = str.Split('_');

     foreach (var intString in splitIntList)
     {
         returnValue.Add(int.Parse(intString));
     }
     return returnValue;
 }

There is probs a more efficient way to do it, but this works fine.

Comment
Add comment · Share
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

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.

Follow this Question

Answers Answers and Comments

169 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

Related Questions

Store Reference to a Serializable Class 0 Answers

Start function dont work 1 Answer

ScriptableObject created from custom editor lose data on Unity restart 1 Answer

Serializable Class On ScriptableObject Null when loaded from AssetBundle 2 Answers

Why Does My Saved Data Not Load? 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