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 Stitchey_ · Nov 02, 2015 at 10:50 PM · arrayarrays

Why is inserting variables into an array not working?

I am trying to insert track_easy, medium and hard into the "tracks" array, and I don't know why it isn't working. Help, please?

 public MusicTrack[] tracks = new MusicTrack[3];
 public int id;
 public string name;

 public MusicKit(string name, int id, MusicTrack track_Easy, MusicTrack track_Medium, MusicTrack track_Hard) {

     this.id = id;
     this.name = name;

     // These are not inserted into the array.
     tracks [0] = track_Easy;
     tracks [1] = track_Medium;
     tracks [2] = track_Hard;

 }
 

}

Comment
Add comment · Show 2
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 saud_ahmed020 · Nov 03, 2015 at 06:24 AM 0
Share

First check your variables value. Are these null ?? And allocate memory to array "tracks" in Start method. like

 public $$anonymous$$usic$$anonymous$$it(string name, int id, $$anonymous$$usicTrack track_Easy, $$anonymous$$usicTrack track_$$anonymous$$edium, $$anonymous$$usicTrack track_Hard) {
      this.id = id;
      this.name = name;
      // These are not inserted into the array.
      if(track_Easy != null)
           tracks [0] = track_Easy;
      if(track_$$anonymous$$edium != null)
          tracks [1] = track_$$anonymous$$edium;
       if(track_Hard != null)     
         tracks [2] = track_Hard;
  }
 void Start()
 {
     tracks = new $$anonymous$$usicTrack[3];
 }

@Stitchey_

avatar image NoseKills · Nov 03, 2015 at 05:04 PM 0
Share

If this is a monobehaviour , you shouldn't have a constructor. If not, the Start function suggested by @saud_ahmed020 won't be called.

Anyways. What do you mean it's "not working"? It can mean a 100 things : code not compiling, getting a null ref error, soune not playing.

Try debugging by Debug.Loggigng out what you are actually putting into the array, and do the same when you try to read from the array and give your class instances id's so you know whether you write and read from the same array or are you e.g. creating duplicates without noticing

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.

Follow this Question

Answers Answers and Comments

33 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

Related Questions

only keep every 10th entry in an array? 2 Answers

Array[] of children of a child 3 Answers

Getting the element that has the same element number on another list ? 2 Answers

Array 2D of data 1 Answer

How do I disable an array of Buttons? 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