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 chomps32 · Sep 03, 2016 at 10:39 PM · destroygetcomponentclonearraylistscope

Component not being accessed in ArrayList

Ok, Here is my problem:

I have 2 classes, GameManager and DrumAnimation.

DrumAnimation is setting a Color variable called Col2 to be private with a public set method.

GameManager has an array of GameObjects with the DrumAnimation Component attached to it. In the coroutine to start a new level. One of the GameObjects in the array is instantiated in an ArrayList. All the GameObjects in the original array are then destroyed and the array is reinstantiated. The last added GameObject in the ArrayList then has it's DrumAnimation component's Col2 set to green.

The problem is that the color of Col2 stays the same when the game is played. Can anybody give me some insight on why this is happening?

Comment
Add comment · Show 4
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 DavidWatts · Sep 03, 2016 at 10:45 PM 0
Share

can we see some sample code?

avatar image chomps32 DavidWatts · Sep 03, 2016 at 11:08 PM 0
Share

@$$anonymous$$Watts

public class DrumAnimation : $$anonymous$$onoBehaviour { Color col2; public Color Col2 { set { col2 = value; } } }

public class Game$$anonymous$$anager : $$anonymous$$onoBehaviour { public GameObject drumPrefab; private GameObject[] drumChoices; private List band$$anonymous$$ates;

 void Start() {
     drumChoices = new GameObject[4];
     band$$anonymous$$ates = new List<GameObject>();

 IEnumerator NewLevel()
 {
     band$$anonymous$$ates.Add((GameObject)Instantiate(drumChoices[index]));
     if (band$$anonymous$$ates[band$$anonymous$$ates.Count - 1].GetComponent<DrumAnimation>() != null)
     {
         band$$anonymous$$ates[band$$anonymous$$ates.Count - 1].GetComponent<DrumAnimation>().Col2 = Color.green;
     }
     else { Debug.Log("DrumAnimation not found"); }

     for(int i = 0; i <drumChoices.Length; i++)
     {
         Destroy(drumChoices[i]);

     }

     for(int i = 0; i< band$$anonymous$$ates.Count; i++)
     {
         band$$anonymous$$ates[i].transform.Translate(0, 2f, 0, Space.Self);
     }

     drumChoices = new GameObject[4];

}

avatar image DavidWatts chomps32 · Sep 03, 2016 at 11:30 PM 0
Share

maybe it is a serialization issue try add [SerializeField] to the private col2 var and see if that helps.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by chomps32 · Sep 09, 2016 at 04:07 PM

Found the problem to be a collision between setting the color after initialization in the GameManager class and setting the color in the Start() method in the DrumAnimation component class. So, I stopped setting the color in the Start() method and it worked just fine. Thanks for your help @DavidWatts

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

57 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

Related Questions

How to destroy more than one clone at runtime??? 1 Answer

How to Clone Array1 into Array2 in Unity? Using JavaScript. 0 Answers

Reference an Instance of an Object?C# 1 Answer

How do I Destroy() powerup and get sound to play? 1 Answer

How to clone an ArrayList? 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