• 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 /
avatar image
2
Question by SARWAN · Jan 16, 2013 at 04:46 AM · c#listdictionaryarraylisthashtable

Combine Children Dictionary in place of Hashtable?

Hi,

       In Combine Children script how to convert the hashtable to Dictionary.

and ArrayList to List? ? ?

Here is coding part of Combine children. .

 void Awake()
 {
 Hashtable materialToMesh = new Hashtable();
 
 ArrayList objects = (ArrayList)materialToMesh[materials[m]];
 if (objects != null) 
 {                        objects.Add(instance);
 }
 else
 {
 objects.Add(instance);
 materialToMesh.Add(materials[m], objects);objects = new ArrayList();
 }

If i changed the Hashtable and ArrayList like this Dictionary materialToMesh= new Dictionary(); List objects = (List)materialToMesh[materials[m]];

It shows and Error. .

Help me to solve this? ?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by iwaldrop · Jan 16, 2013 at 11:16 PM

It's because you have to tell the compiler what types of data the Dictionary is going to hold:

 Dictionary<byte, object> op = new Dictionary<byte, object>();

Additionally, in order to create Lists you need to do the following:

 List<float> floats = new List<float>();
Comment
Add comment · Show 6 · 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
avatar image SARWAN · Jan 17, 2013 at 05:01 AM 0
Share

Yes. I did that, but still facing the error .

Dictionary materialTo$$anonymous$$esh= new Dictionary(); $$anonymous$$eshCombineUtility.$$anonymous$$eshInstance instance = new $$anonymous$$eshCombineUtility.$$anonymous$$eshInstance (); List objects = (List)materialTo$$anonymous$$esh[materials[m]];

Error it shows is: Error 114 Cannot convert type 'UnityEngine.$$anonymous$$esh' to 'System.Collections.Generic.List'

avatar image iwaldrop · Jan 17, 2013 at 05:59 AM 0
Share

Well, the error says it all; you're attempting to cast the Value of materials[m] as a List (which appears to be a $$anonymous$$esh by looking the error).

If you're trying to take all the Values of a Dictionary and put them into a List then you need to do something like the following:

 List<$$anonymous$$esh> meshes = new List<$$anonymous$$esh>();
 materialTo$$anonymous$$esh.Values.ForEach(m => meshes.Add(m));
avatar image SARWAN · Jan 17, 2013 at 06:09 AM 0
Share

https://www.assembla.com/code/bolaDePano/subversion/nodes/Assets/Standard%20Assets/Scripts/CombineChildren.cs

Here is the Link of the Script that i got error in the conversion. Look out it.

avatar image iwaldrop · Jan 17, 2013 at 07:04 AM 1
Share

Neat script. Sorry, but this is a little above my pay grade. I hope that someone else can give you an answer. I've bumped it so maybe somebody will take notice. Good luck!

avatar image SARWAN · Jan 17, 2013 at 10:43 AM 0
Share

Thanks for your reply

Show more comments
avatar image
0

Answer by SARWAN · Jan 17, 2013 at 06:42 AM

@iwaldrop
Yes I Already did the same thing only. But i didn't put in the code part so only it shows like that. I changed that to

 Dictionary<Material,Mesh> materialToMesh= new Dictionary<Material,Mesh>();    
 for (int i=0;i<filters.Length;i++) {
 ..
 ..
 MeshCombineUtility.MeshInstance instance = new MeshCombineUtility.MeshInstance ();
 ...
 ...
 ...
 Material[] materials = curRenderer.sharedMaterials;
                 for (int m=0;m<materials.Length;m++) {
                     instance.subMeshIndex = System.Math.Min(m, instance.mesh.subMeshCount - 1);
                     List<MeshCombineUtility.MeshInstance> objects = (List<MeshCombineUtility.MeshInstance>)materialToMesh[materials[m]];

But it shows an error as Error 114 Cannot convert type 'UnityEngine.Mesh' to 'System.Collections.Generic.List'

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.

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

9 People are following this question.

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

Related Questions

Add a Play Next Song And A shuffle Option To Music Player C# 1 Answer

Add value to List without replacing previous 0 Answers

A node in a childnode? 1 Answer

From two lists into a dictionary... and back? 5 Answers

How to alphabetically sort your List? 2 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