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 gabrielstuff · Aug 23, 2013 at 11:12 AM · listempty

[RESOLVED] List get empty after certain time.

Hi ! I'm pretty new to unity but already enjoying it. I'm playing with tween and gameObject property. This very basic script allow one to have 3 connected object with the wonderfull vectrosity line editor.

This works perfectly, but... after a certain time of runtime the list where I store all my reference to the line got empty.

Here is the class bellow. Please note that I encounter the problem everytime the app run more than few minutes.

Would be nice to get some help.

thank you,

 using UnityEngine;
 using Holoville.HOTween;
 using System.Collections;
 using System.Collections.Generic;
 using Vectrosity; 
 
 
 public class Line : MonoBehaviour {
     private List<VectorLine> connectionList = new List<VectorLine>();
     private int childrenNumber;
     
     [Range(1.01f, 1.10f)]
     public float variation;
     
     public Material lineMaterial;
     [Range(0.1f, 10.0f)]
     public float stroke;
     
     //private Material materialLine;
     
     void Start() {
         HOTween.Init(true, true, true);
         
         childrenNumber = this.transform.childCount;
         var linePoints = new Vector3[2];    
         if(childrenNumber >= 2){
             for(int i = 0; i < childrenNumber; i++){
                     linePoints[0] = transform.GetChild(i).position;
                     if(i < childrenNumber - 1){
                         linePoints[1] = transform.GetChild(i+1).position;
                     } else {
                         linePoints[1] = transform.GetChild(0).position;
                     }
                     linePoints[0].z = linePoints[0].z + 0.2f;
                     linePoints[1].z = linePoints[1].z + 0.2f;
                     var lineName = "MyLine"+i;
                     connectionList.Add(new VectorLine(lineName, linePoints, lineMaterial, stroke));
                     connectionList[i].Draw3D();
                     HOTween.To(transform.GetChild(i), 3, new TweenParms()
                         .Prop("position", new Vector3(transform.GetChild(i).position.x + Random.Range(-0.50F, 0.50F), transform.GetChild(i).position.y + Random.Range(-0.50F, 0.50F), transform.GetChild(i).position.z + Random.Range(-0.50F, 0.50F)), false) // Position tween (set as relative)
                         .Loops(-1, LoopType.Yoyo) // Infinite yoyo loops
                         .Ease(EaseType.EaseInOutQuad) // Ease
                         .OnStepComplete(moveComplete, transform.GetChild(i).name) // OnComplete callback
                     );
             }        
         }
     }
     
     void Update() {
         childrenNumber = this.transform.childCount;
         if(childrenNumber >= 2){
             if(connectionList.Count < childrenNumber){
                 Debug.Log(connectionList.Count);
             } else {
                 for(int i = 0; i < childrenNumber; i++){
                         connectionList[i].points3[0] = transform.GetChild(i).position;
                         if(i < childrenNumber - 2){
                             connectionList[i].points3[1] = transform.GetChild(i+1).position;
                         } else {
                             connectionList[i].points3[1] = transform.GetChild(1).position;
                         }
                         connectionList[i].points3[0].z += 0.2f; 
                         connectionList[i].points3[1].z += 0.2f; 
                         connectionList[i].lineWidth = stroke;
                         connectionList[i].Draw3D();
                 }
             }
         }
     }
     
     void moveComplete(TweenEvent data){
         if ( data.parms != null ) {
             Debug.Log( data.parms[0] ); // outputs 1
           }
         Debug.Log("complete");
     }
     
     void OnMouseDrag() {
         renderer.material.color -= Color.white * Time.deltaTime;
     }
 }
 
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 meat5000 ♦ · Aug 23, 2013 at 11:40 AM 0
Share

Doesn't 'this' refer to the script itself? I'm sure I found that when I used it in the past. Take out 'this' and see what happens.

  void Update() {
            childrenNumber = transform.childCount;
avatar image neonblitzer · Aug 27, 2013 at 08:34 PM 0
Share

You should probably post your comment as an answer and mark this question answered.

1 Reply

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

Answer by gabrielstuff · Aug 23, 2013 at 12:41 PM

I change the line : private List connectionList = new List();

to :

  private List<VectorLine> connectionList ;

and I instantiate the list at Start...

this seams to fix the problem.

Thanks

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

16 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

Related Questions

A node in a childnode? 1 Answer

List Emptying Itself? 1 Answer

Need to display strings in a List<> in a GUILayout.SelectionGrid 1 Answer

Populating a list with different items in different clones of the same prefab. 0 Answers

InvalidOperationException Collection was modified; 3 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