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 Momeka · Aug 11, 2011 at 07:15 PM · arraylistupdateemitter

List is empty in Update

So I have a list that I add objects to in another functions, and when I added the object the list count is correct. But when I loop through the list in the update it thinks the count is zero.

  #region Members

 //Array of all the particles
 public Transform[] particles;

 List<Transform> ap = new List<Transform>();

 public int count = 0;

 #endregion

 public void UpdateEmitting()
 {
     count = ap.Count;

     for (int i = ap.Count - 1; i >= 0; i--)
     {
         baseParticle bp = ap[i].GetComponent("baseParticle") as baseParticle;

         if (bp == null)
             Debug.LogError(" can't find baseParticle");
         else
         {

             bp.UpdateEmitting();

             bp.SetPosition();

             if (bp.dead)
             {
                 bp.StopEmitting();
                 ap.RemoveAt(i);
             }
         }
     }
 }

 /// <summary>
 /// Starts emitting particles
 /// </summary>
 /// <param name="name">Name of the emitter to start</param>
 /// <param name="t">The transform to emit particles from</param>
 public void StartEmitting(string name, Transform t)
 {
     foreach (Transform p in particles)
     {
         baseParticle bp = p.GetComponent("baseParticle") as baseParticle;
         if (bp != null)
         {
             if (bp.name == name)
             {
                 ap.Add((Transform)Instantiate(p, t.position, t.rotation));
                 bp.StartEmitting();

                 if (t != null)
                     bp.emitPosition = t;

                 Debug.Log("add count:" + active.Count);
                 return;
             }
         }
     }
     Debug.Log("No emitter found");
 }

 public void StartEmitting(string name, Vector3 pos, Quaternion rot)
 {
     foreach (Transform p in particles)
     {
         baseParticle bp = p.GetComponent("baseParticle") as baseParticle;
         if (bp != null)
         {
             if (bp.name == name)
             {
                 ap.Add((Transform)Instantiate(p, pos, rot));
                 bp.StartEmitting();
                 bp.SetPosition(pos, rot);
                 bp.emitPosition = null;
                 return;
             }
         }
     }
     Debug.Log("No emitter found");
 }

 /// <summary>
 /// Stop emitting particles
 /// </summary>
 /// <param name="name">Name of the particle to stop emitting</param>
 public void StopEmitting(string name)
 {
     for (int i = ap.Count - 1; i >= 0; i--)
     {
         baseParticle bp = ap[i].GetComponent("baseParticle") as baseParticle;

         if (name == bp.name)
         {
             bp.StopEmitting();
             ap.RemoveAt(i);
         }
     }
 }
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 Julien-Lynge · Aug 11, 2011 at 07:22 PM 0
Share

Can you add some debug output and run your script to help us figure out what you're doing? I don't see any update or start functions, so I don't know where you're entering this series of functions and what order things are firing in. With your debug, can you output the count of ap at each step?

avatar image Momeka · Aug 11, 2011 at 07:53 PM 0
Share

The update is called from a $$anonymous$$onoBehaviour update call in another script. The ap.count during the updateEmitter it's always zero. But in the StartEmitting and StopEmitting the count is always correct to how many objects is added in the list.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

What do you think of this? List, Vector 3 and Update 1 Answer

Updating Array inside a List 1 Answer

List/Array Not Updating 2 Answers

Javascript Endless 3D Array 0 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