first to clear something out, the function i wrote is probably not the best practice, but it was done fast and it works, but later i discovered that memory used increases every time i use this function...so i guess there is some kind of problem with arrays... can you help me out. memory used increases pretty fast it renders function useless....
here is the code:
//REMOVE ALL OBJECTS THAT ARE OUTSIDE CUT OFF DISTANCE
function RemoveObjectsOutsideCutoffDistance(center : Vector3){
//ONLY REMOVE IF WE ARE IN NORMAL MODE
if(currentViewState==viewState.normal || currentViewState==viewState.region){
var objectsToShow=new Array();
//GO THROUGH ALL SYSTEMS
for(i=0;i<TrackingControl.Systems.length;i++){
//CHECK IF SYSTEM IS LOADED AND VISIBLE
if(TrackingControl.Systems_.isLoaded && TrackingControl.Systems*.isVisible){*_
_*//GET THE COLLIDERS OF OBJECTS THAT ARE INSIDE THE SPHERE COLLIDER*_
<em>_var colliders=Physics.OverlapSphere(center,TrackingControl.Systems*.radius);*_</em>
<em>_*//MAKE AN ARRAY OF OBJECTS THAT WE ARE GOING TO SHOW*_</em>
<em>_*for(var e=0;e<colliders.length;e++){*_</em>
<em><em>_if(colliders[e].tag==TrackingControl.Systems*.tag){*_</em></em>
<em><em>_*if(!colliders[e].gameObject.GetComponent("Highlight").hidden){*_</em></em>
<em><em>_*objectsToShow.Push(colliders[e].transform);*_</em></em>
<em><em>_*}*_</em></em>
<em><em>_*}*_</em></em>
<em><em>_*}*_</em></em>
<em><em>_*//HIDE ALL OBJECTS IN THE SYSTEM*_</em></em>
<em><em><em>_var Objects : GameObject[]=GameObject.FindGameObjectsWithTag(TrackingControl.Systems*.tag);*_</em></em></em>
<em><em><em>_*for(k=0;k<Objects.length;k++){*_</em></em></em>
<em><em><em>_*Objects[k].renderer.enabled=false;*_</em></em></em>
<em><em><em>_*Objects[k].gameObject.layer=2;*_</em></em></em>
<em><em><em>_*}*_</em></em></em>
<em><em><em>_*}*_</em></em></em>
<em><em><em>_*}*_</em></em></em>
<em><em><em>_*//COPY "OBJECTS TO SHOW" INTO GLOBAL ARRAY THAT TRACKS VISIBLE OBJECTS IN THE SCENE*_</em></em></em>
<em><em><em>_*//WE CAN USE THAT ARRAY TO HANDLE WHAT OBJECT TO SHOW WHEN IN HIDDEN MODE*_</em></em></em>
<em><em><em>_*if(currentSeeThroughState==seeThroughState.hidden){*_</em></em></em>
<em><em><em>_*visibleObjects=objectsToShow;*_</em></em></em>
<em><em><em>_*}*_</em></em></em>
<em><em><em>_*//UNHIDE THE ONES THAT ARE INSIDE THE SPHERE*_</em></em></em>
<em><em><em>_*for(j=0;j<objectsToShow.length;j++){*_</em></em></em>
<em><em><em>_*if(!objectsToShow[j].gameObject.GetComponent("Highlight").hidden){*_</em></em></em>
<em><em><em>_*objectsToShow[j].renderer.enabled=true;*_</em></em></em>
<em><em><em>_*objectsToShow[j].gameObject.layer=0;*_</em></em></em>
<em><em><em>_*RemoveHighlight(objectsToShow[j].transform);*_</em></em></em>
<em><em><em>_*}*_</em></em></em>
<em><em><em>_*}*_</em></em></em>
<em><em><em>_*}*_</em></em></em>
<em><em><em>_*```*_</em></em></em>
<em><em><em>_*<p>}</p>*_</em></em></em>
<em><em><em>_*<p>what is happening here is that i want to remove all objects from the scene that are not inside the sphere that*_</em></em></em>
<em><em><em>_*has radius determined in other script. so i get all objects (from different systems in the scene- tracking control) that are in the sphere, copy all the objects in the array objectsToShow, then hide all objects in the scene and then unhide that ones that are in the objectsToShow. There is also a case where we copy that array to other global array, but that is irrelevant now, since memory goes up when we are outside that state.</p>*_</em></em></em>
<em><em><em>_*<p>it works fine but only things that worries me is that memory leaks....i do not know why, do i need to clear arrays? they should be alive only inside the function.</p>*_</em></em></em>
<em><em><em>_*<p>thanks in advance! any help appreciated!</p>*_</em></em></em>
<em><em><em>_*<p>cross post to forums: <a href="http://forum.unity3d.com/threads/79548-problem-with-memory-leak..-please-help-me-solve-it" rel="nofollow">http://forum.unity3d.com/threads/79548-problem-with-memory-leak..-please-help-me-solve-it</a></p>*_</em></em></em>