- Home /
[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;
}
}
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;
You should probably post your comment as an answer and mark this question answered.
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
Your answer
![](https://koobas.hobune.stream/wayback/20220613112817im_/https://answers.unity.com/themes/thub/images/avi.jpg)