Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 michael 4 · May 01, 2011 at 04:50 PM · arraylistrts

<List> wont generate correctly

I have this code that is supposed to Load all the gameobjects in the resource folder into an array, parse the information and then generate a List of objects from it.

The problem is when i try to loop through the array to create a List of objects (building types). The array hold the correct data, but the final List just has the final Object in each in every member of the List.

For example the List is supposed to come out like

a b c d

but instead it comes out like

d d d d

I hope this all makes since, here is my code, Ive been looking over it for 3 days now and i just cant come up with anything, I hope someone can help

here is the building type class just for your reference

    public class Building : System.Object 

{ public GameObject buildingModel; public string buildingName; public int buildingIndex; public Material buildingTexture; public Texture buildingIcon;
}

but here is the actual code that I cant seem to get working correctly

public void LoadFilesIntoArray() {

 Building building = new Building();

 Object[] buildingList = Resources.LoadAll(datasetName,typeof(GameObject)); //these fbx objects must be collasped to single mesh to work properly

 for(int i = 0; i &lt; buildingList.Length; i++)
 {
     building.buildingModel = buildingList[i] as GameObject;
     building.buildingName = buildingList[i].name as string;
     building.buildingTexture = building.buildingModel.renderer.material; //save the initial material
     buildingPallete.Add(building);
 }       

}

void OnGUI() { foreach(Building b in buildingPallete) { Debug.Log(b.buildingName); } }

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
2
Best Answer

Answer by benni05 · May 01, 2011 at 05:28 PM

Put

Building building = new Building();

inside the for loop.

Comment
Add comment · Show 3 · 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 GesterX · May 01, 2011 at 05:48 PM 0
Share

just to expand on that - it should be the first line inside the for loop

avatar image michael 4 · May 01, 2011 at 11:47 PM 0
Share

haha thanks so much thats all it took, makes me feel pretty dumb thats like the last thing i hadnt tried ;p

avatar image benni05 · May 02, 2011 at 10:32 AM 0
Share

Feel free to accept my anser as the correct one :)

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

No one has followed this question yet.

Related Questions

A node in a childnode? 1 Answer

destroying a unit and removing it from a list 2 Answers

How to add gameobject inside of an array? 0 Answers

How to return index of List element? 1 Answer

How can I instantiate parented ui objects above previously instantiated children? 1 Answer


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