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 /
avatar image
0
Question by JuanForero · Sep 29, 2019 at 04:23 AM · objectlistdatadynamicaccess

How to access the data in a list that save any class inside

I need to acces a data from a list of any class inside of this list

how you can do that?

   List<object> dynamic_list;
   dynamic_list.Add(node);    
   dynamic_list[i].node.current_pos;  // dont work when you access like a normal list, list<normal_class> normal_list
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 Bunny83 · Sep 29, 2019 at 04:38 AM

Well all your elements in your list are references of type object. You have to manually cast the reference to the proper type in order to access any type specific fields, properties or methods of that type. So either:

 YourNodeType n = (YourNodeType)dynamic_list[i];
 n.node.current_pos;

Or just inline by using brackets:

 ((YourNodeType)dynamic_list[i]).node.current_pos;

Note that using an untyped array / list can cause a lot issues. First of all casting requires runtime type checking which can be quite slow if you use this often. Second if you try to cast an "object" to the wrong type your code will throw an exception and will terminate the execution. Why do you actually use an untyped list? If you want to mix different types, how have you planned to figure out what kind of object is in which element? What kind of different data you want to store in that list? What is the actual reason why you need those different types in one list? Do those different objects have anything in common?

Comment
Add comment · Show 2 · 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 JuanForero · Sep 29, 2019 at 04:57 AM 0
Share

Hi @Bunny83 thanks for your answer, I wanted to know, how to make a network of list, and conect list with other list, like a pointers in c++, in the most dynamic way possible , but for now this is the most close way that I know, so how you can create a struct or list or type or without type thing that can save and conect data very dynamically like Hyper Procedural Dynamic List on Unity?

avatar image Mouton JuanForero · Sep 29, 2019 at 11:02 AM 0
Share

@JuanForero I edited my answer on your original topic (https://answers.unity.com/questions/1668265/i-neet-to-make-like-a-hyper-procedural-dynamic-lis.html) to add an example on how to typecast your elements in the list. However, if what you are trying to achieve is a list of list, you can just do it like so in C#:

 List<List<YourType> > listNestingLists = new List<List<YourType> >();

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

123 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

Related Questions

A node in a childnode? 1 Answer

List in prefab instantiated object not saving after Awake 0 Answers

How to access List<> from other script? 1 Answer

Modifying each object in a list, with different modifiers? 0 Answers

Can I make a list of hashtables or classes with pragma strict 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