Quantcast
Channel: Questions in topic: "unloadunusedassets"
Viewing all 85 articles
Browse latest View live

Resource Unload - Doesn't clear memory fully

$
0
0
Hello, I'm trying dynamically load and then unload a prefab at runtime via Resource Load/Unload. But every time I unload the prefab, I don't get all my memory back: ![alt text][1] As you can see, at the start, the app is running normally. I then load in the prefab which then causes the large spike as expected, I then remove the prefab, but the memory doesn't go back down to the starting height. I only get about 25% of my memory back. Why is this? How I load: //get the prefab directory and load request = Resources.LoadAsync( "_SteamingPrefabs/" + GetPrefabName(story, page) ); //visual UI while(request.isDone == false){ var _f : float = request.progress * 100; progressWheel.SetPercentage( _f ); yield; } //resource object itself loadedResource = request.asset; //make clone of prefab loadedPrefab = Instantiate(loadedResource) as GameObject; How I unload: request = null; children = loadedPrefab.GetComponentsInChildren.(true); for(var i = children.length-1; i >= 0; i--){ UnityEngine.Object.Destroy(children[i].gameObject); children[i] = null; } children = null; UnityEngine.Object.Destroy(loadedPrefab); loadedResource = null; loadedPrefab = null; yield WaitForEndOfFrame(); yield WaitForEndOfFrame(); Debug.LogWarning("[SERIAL] Unloading Resources"); yield Resources.UnloadUnusedAssets(); yield WaitForEndOfFrame(); Resources.UnloadUnusedAssets(); Is there something I'm missing here? I'm searching endless forums and threads, and I still don't know what I'm doing wrong?? Whats interesting, is that if I load the prefab back in - the memory goes back to the original height. Etc. [1]: /storage/temp/66082-screen-shot-2016-03-16-at-220028.png

Unloading scenes after ServerChangeScene

$
0
0
Hi! I've been messing around with UNET for a couple of months now and it feels like I've finally gotten the hang of it. However I've found something (perhaps not entirely related to UNET) that I can't really find any information on. Everytime after I use ServerChangeScene on the NetworkManager, my logs seem to get spammed with "unloading X unused assets to reduce memory usage." It seems this process is repeated for the same few objects a ton of times and after the first time, it doesn't actually reduce the amount of objects in the scene. When I check it out in the Editor, the scenes pop up in my hierarchy (presumably the SceneManager doing its thing), and there's a ton of not loaded duplicates of the level I'm trying to load, rapidly being removed from the hierarchy. This takes a bit of time which I want to shave off. Did anyone have the same problem and a viable solution to it? I've attached a screenshot of how it looks in the hierarchy. ![alt text][1] [1]: /storage/temp/67608-unloading-scenes.png

Script for unloading assets and textures?

$
0
0
Hi, so basically i have memory problems with my game it use so much ram about 3,5 GB and after about a 30minutes of playing my game it crashes. Last 3-4 days i was searching whole internet for some script that can Unload assets or textures but the only thing i found was some lines of code what people posted but that doesn't help me at all. So please please! Is there any good soul that can write some kind of that script and post it here? I'm som confused and angry because i cannot go further with developing my game. I cannot enjoy gameplay with my friends longer than 25-30 minutes because the game crashes every time for running out of memory. Here is the link to my game if you want to check it: http://gamejolt.com/games/thuglifealpha/61660 Thanks for any replies ! :) Here's some photo of problem: ![alt text][1] [1]: /storage/temp/73471-snimka-obrazovky-884.png

using UnloadUnusedAssets() to remove www.texture from memory cause freezing

$
0
0
I have a coroutine loading textures from a folder. When loading a new texture I need to unload the other textures from memory(I think I have read all the threads on this issue), the only thing that seem to work is UnloadUnusedAssets(). However it freezes unity. What can I do? Is it better to use UnloadAsset()? but I dont know what to feed that function with to clear the unused textures. public IEnumerator setDecalTexture() { www = new WWW("file:///"+decalTextureFiles[selectedDecal].FullName); yield return www; CarBodyRenderers= this.gameObject.GetComponentsInChildren(); foreach(Renderer rend in CarBodyRenderers){ if(rend!=null){ foreach(Material matt in rend.materials){ if(matt.name == decalMaterialName|| matt.name == decalMaterialName+" (Instance)"|| matt.name == decalMaterialName+" (Instance) (Instance)"){ if(www!=null&& decalMaterialName!= null && www.isDone==true)matt.mainTexture=www.textureNonReadable; } } } } //www.Dispose(); //www = null; //System.GC.Collect(); Resources.UnloadUnusedAssets(); currentDecal=selectedDecal; Debug.Log("setDecalTexture()"); } ![alt text][1] [1]: /storage/temp/79852-unloadassetsfreeze.png

Best practice for cleaning up leaked procedural materials?

$
0
0
As is reasonably well-documented, when you modify renderer.material on a gameObject, it makes a new copy of the material, and that copy is not automatically destroyed when the gameObject is. This can cause memory leaks. You can clean up these leaks by calling Resources.UnloadUnusedAssets() periodically, but that feels sloppy and almost definitely has unnecessary overhead. Theoretically, Resources.UnloadAsset() looks like a manual alternative, but it isn't working for me. My materials are ProceduralMaterials (Substance Designer) and when I call UnloadAsset on one, it throws this exception: > UnloadAsset can only be used on assets: UnityEngine.Resources.UnloadAsset(Object) I've seen suggestions to use DestroyImmediate, that doesn't seem to work either. Is there a way to manually unload procedural materials? Should I just get over it and write a script to call UnloadUnusedAssets every couple minutes?

Question about asset memory not freed after calling SceneManager.UnloadSceneAsync()

$
0
0
For SceneManager.UnloadSceneAsync in documentation it says:> Note that assets are currently not> unloaded, in order to free up asset> memory call Resources.UnloadAllUnusedAssets. Does this mean that asset memory will never be free up until i call Resources.UnloadAllUnusedAssets() and then i have to call it everytime i call SceneManager.UnloadSceneAsync? Or it will be freed later automatically?

Are My AssetBundles Being Unloaded On Me Without My Doing So?

$
0
0
I have a very strange issue I'm hoping someone could shed some light on (mobile app)... at least offer somewhere to look. I have 6 AssetBundles in my game that are getting loaded at startup. I create an assetDictionary of name-references for all the objects in my AB's. Then, when I need one of those assets, I'm use the dictionary to point to the correct AB from which I attempt to LoadAsset. However, in my "new install flow", when I attempt to LoadAsset from an AssetBundle, it returns null. If I run once more (now not through my "new install flow" - some user profile data has been stored on disk), those same LoadAsset calls which returned null now return their valid objects. Obviously, I could simply have some mysterious problem in my code, but I believe this started happening when I went from 5 AB's totaling 15MB in size to 6 AB's totaling 27MB. I also read in some of the documentation that once we're out of caching space, the least recently used AB will be unloaded. So, I'd love to find a way to see a log or event when the AB gets unloaded on me, if this is happening; or at least have some way of knowing the status of my AssetBundle... viewing its object in the debugger at runtime offers zero insight into the availability of its contents. Any assistance here would be much appreciated. Thanks.

load/unload large scene help

$
0
0
I have a very large scene, extremely large. I was wondering if there is a way to split it up and only load sections of it at a time. Here is a picture to help illustrate my problem. ![http://i54.tinypic.com/iodthd.jpg][1] Imagine the character is currently in 2C. I would like to load the terrain for: ----- 1B, 2B, 3B, 1C, 2C, 3C, 1D, 2D, 3D. ---- Of course, this is only terrain. To even better save on data, could I only load assets within proximity of the player? Proximity being not just objects within those regions of space, but like... around the player. How would I go about this? I can just see so many problems... Im not much of an expert with Unity so... Yeah. Is there already sample code for this? It seems I would have to build a list/array of the scenes... but I have no idea how I would do that. Nor how the Vector3 would transfer from scene to scene. I was thinking I could make seperate terrains and load them all individually based on proximity.. but I dont know how to go about that either. Any help? [1]: http://i54.tinypic.com/iodthd.jpg

Out of memory loading between levels

$
0
0
Howdy Unity gurus!!! I get out of memory errors now and then just before loading scene "y" from secene "x". Scene"x" is moderate size, not tiny. Scene "y" only has two objects. One with a 1024 texture. I'm trying the following: Resources.UnloadUnusedAssets() just before loading scene"y" but I'm not using any resource bundles. Would this have any effect? I'm assuming it would dump some memory. Thx for any tips in advance on this issue.

DX Crash, GFXDevice Crash

$
0
0
I am experiencing a crash consistently that prints to the unity logs the following information: HandleD3DDeviceLost HandleD3DDeviceLost: still lost Skipped rendering frame because GfxDevice is in invalid state (device lost) I've searched and I've read and a lot of people associate this crash with Unity's Multi-Threaded rendering, but I've turned this off and still find the crash. I have no way to reproduce the crash I can only look at the logs around when it happened. It would appear from the logs that the crash happens just after I clear unused assets with the following: Resources.UnloadUnusedAssets(); System.GC.Collect(); In the logs this appears when it works as: Unloading 1 unused Assets to reduce memory usage. Loaded Objects now: 377. Operation took 4.403515 ms. Unloading 0 Unused Serialized files (Serialized files now loaded: 0 / Dirty serialized files: 0) And when the crash occurs as: Unloading 1 unused Assets to reduce memory usage. Loaded Objects now: 377. Operation took 4.344816 ms. Skipped rendering frame because GfxDevice is in invalid state (device lost) (Filename: C:/BuildAgent/work/14194e8ce88cdf47/Runtime/Misc/Player.cpp Line: 1617) HandleD3DDeviceLost HandleD3DDeviceLost: still lost Skipped rendering frame because GfxDevice is in invalid state (device lost) The crash spams the logs until the application is shut down, The application is built for windows and is being tested on a Desktop running Windows XP Professional. Can anyone shed some light on this? **EDIT** I don't believe the gfxdevice crash is caused by any of the clearing memory code as I've changed it and the crash is still present.

Asset is not unloaded even if GameObject destroyed

$
0
0
I believe that this question was discussed many times, but still. Consider an example: We have some kind of singleton class which exists all the time. It has public GameObject MyGameObject; We load scene1. And set MyGameObject = GameObject.Find("Whatever"); Then we load scene2. Now Debug.Log(MyGameObject == null) will say "true". I suppose somekind of wrapper still exists, which knows that this GameObject doesn't exists anymore. We can't even find it using FindObjectsOfTypeAll (and we can't find source asset). So Unity knows that object was destroyed, but it still keeps texture alive! (after calling UnloadUnusedAssets of course). So until we excatly set MyGameObject = null; we can't get rid of texture it uses in our memory. This is very simple example, in reality everything can be very unobvious. We can reference another class, which can refenrece gameobject which was destroyed and it's component can has delegate in which closure still exists local variable of another gameobject and etc.. I understand that this is our problem and we should keep eyes on our code, but I'm really interested in reasonable explanation why is it so?

Call UnloadUnusedAssets after SetQualityLevel?

$
0
0
If I change quality settings will the old textures be cleared from memory straight away or should I use UnloadUnusedAssets?

Assets not unloading on scene change in Android (works on iOS)

$
0
0
So I've got a strange problem, I can't seem to unload assets between scenes in my app. On iOS everything is fine, but on Droid the memory usage just keeps going up and the profiler shows that the NGUI atlases from each scene are all in memory at once. I load new scenes through a loading screen scene (to ensure minimal assets are required) and there are numerous calls to Resources.UnloadUnusedAssets and GC.Collect between levels. None of my assets appears to ever unload however. I'm trying to figure out why this happens only on Android. Any clues would be welcome.

Unload Resources

$
0
0
Let's say i've a gameobject which has a compoment with a used resource. I set the gameObject to inactive, but later i'd like to set it to active I call Resources.UnloadUnusedAssets(); Does it delete the resource from the memory, and when i change the gameObject to active is it loaded?

Resources.UnloadUnusedAssets() doesn't always work. How can I find out why?

$
0
0
Hi, So I've hit that point in my Unity programming development where I've come to realise that assets don't get unloaded when you destroy everything that uses them, or clear all the references to them. So, that was a surprise. Anyway, I've added a bunch of code to remove the unwanted assets (looking primarily at textures/atlases which are used by NGUI), being suitably diligent about waiting a couple of frames between destroying objects and/or nulling references and calling UnloadUnusedAssets() because of NGUI's quirk of keeping references about for longer than you think it does. All of my changes have helped, but there are a couple of textures that resolutely refuse to be cleaned up. They show up in the memory profiler. I'd like to know how to find out WHY they show up in the memory profiler. How can I find out which components in the scene reference these texture assets, when running on an iOS device? Is there some kind of runtime script which can tell me something like what you get in the editor with "Find References in Scene"? Is there any way I can get any more information about why certain things are holding references even though it appears as though their references have been changed, or set to null?

UnloadUnusedAssets

$
0
0
I have a script that load a 2048px texture from a Resources folder follow an index (FrameINT): #pragma strict var OBJ : GameObject; var TextName : String = ""; var FrameINT : int ; var FrameOLD : int; var Tempo : float = 0.0; var velocity : float = 0.05; function Awake () { OBJ.renderer.material.SetTexture("_MainTex", Resources.Load(TextName + Manager.SceneNumber.ToString()+ "_" + Manager.Frames.ToString(), Texture)); } function Start () { } function Update () { FrameOLD = FrameINT; FrameINT = Manager.Frames; if ( !Manager.FadeON && FrameOLD != FrameINT){ OBJ.renderer.material.SetTexture("_MainTex", Resources.Load(TextName + Manager.SceneNumber.ToString()+ "_" + FrameINT.ToString(), Texture)); } if (Manager.FadeON){ AssignTexture(); } } function AssignTexture () { OBJ.renderer.material.SetTexture("_MainTexture2", Resources.Load(TextName + Manager.SceneNumber.ToString() + "_" + FrameINT.ToString(), Texture)); if (Tempo < 1.0){ Tempo = Tempo + velocity; OBJ.renderer.material.SetFloat("_Blend", Tempo); } else if (Tempo >= 1.0){ OBJ.renderer.material.SetTexture("_MainTex", Resources.Load(TextName + Manager.SceneNumber.ToString() + "_" + FrameINT.ToString(), Texture)); Tempo = 0.0; OBJ.renderer.material.SetFloat("_Blend", Tempo); Resources.UnloadUnusedAssets(); Manager.FadeON = false; Manager.TouchON = true; } } This system work great and give me possibility to load a large number of big size texture. At first, the application works fine, but with each new load gets too slow. I try to use : Resources.UnloadUnusedAssets(); to unload unused assets but seem not to work. There is a right way to unload unused texture and speed up my application?

Does Resouces.UnloadUnusedAssets frees asset bundles unused resources?

$
0
0
I have game which uses resources as actively as asset bundles. Loading logics is quite primitive: try to load from resources, if not found, WWW.LoadFromCacheOrDownload. And I'm thinking about freeing resources. I use Resources.UnloadUnusedAssets(), but don't use AssetBundle.Unload() method. In editor profile it seems that all unused resources from assets are properly deallocated(I don't know whether by garbage collector or by Resources.UnloadUnusedAssets method). Now I'm wondering, shall I use AssetBundle.Unload or leave it as is? Will everything be ok on phones or there always be memory leaking? I develop for android & ios.

Does UnloadUnusedAssets() unload non-active or occlud

$
0
0
Hello! Does Resources.UnloadUnusedAssets(); unload assets that are simply non-active and/or occluded? The docs don't mention that specifically, but I'd very much like to know. Thanks!

UnloadUnusedAssets - what exactly does "unused" mean

$
0
0
I have some problems understanding what exactly "unused" means for Resources.UnloadUnusedAssets. From the docs:> An asset is deemed to be unused if it isn't reached after walking the whole game object hierarchy, including script components. Static variables are also examined.> The script execution stack, however, is not examined so an asset referenced only from within the script stack will be unloaded and, if necessary, loaded back in the next time one of its properties or methods is used. This requires extra care for assets which have been modified in memory. Make sure to call EditorUtility.SetDirty before an asset garbage collection is triggered. I'm using C#, and my questions are: - static variables: does it mean ALL static variables of ANY C# class in ANY loaded assembly? (public/private/protected)? - what is meant by the "script stack"? is it the execution stack of c#? - what about fields of normal C# instances (non MonoBehaviour) that reference C# instances corresponding to assets, and themselves are references from a MonoBehaviour on an existing GameObject. E.g. MyMonoBehaviour has a private field of type MyClass which has a field myTexture of type Texture2D. Is this deemed as "used" or "unused"? ------ Edit 1 ------ I mainly load resources dynamically using WWW, so at many times they are not (yet) referenced anywhere in the scene. Yet still it's hard to construct a simple case where, based on my understanding of the docs, I could say in advance if the resource will be still valid at some point or not. Here is an example: public class UnloadUnusedAssetsTest : MonoBehaviour { class MyClass { private Texture tex; public MyClass(Texture tex) { this.tex = tex; } public Texture Get() { return tex; } } private MyClass myClass; IEnumerator Start () { var path = "file://" + Application.dataPath + "/../../TestConfig/Images/ImageSmall_01.png"; var www = new WWW(path); yield return www; myClass = new MyClass (www.texture); Debug.Log(myClass.Get().width); www.Dispose(); www = null; GC.Collect(); var unloader = Resources.UnloadUnusedAssets(); while (!unloader.isDone) { yield return null; } Debug.Log(myClass.Get().width); } } In the above example, I expect the texture referenced by myClass.tex to have been unloaded at the last line in the method, but it is not the case, even if: - myClass.tex is not referenced anywhere in the scene - myClass.tex is not directly available from any MonoBehaviour in the scene - i did a cleanup of the loading WWW - and waited for UnloadUnusedAssets() to finish. ------ Edit 2 ------ made an answer out of this edit. Thanks!

Resources.Load have a bad performance

$
0
0
I'm trying to play a movie in Android by using SpriteRenderer because MovieTexture can't be used for Android. Basically, I convert the movie into images and load it as Sprite and assign it to a SpriteRenderer every frame. I put the images in Resources/Movie folder and use this code to load the Image. (Variable counter is what frame the movie currently playing) Sprite GetFrame(){ Sprite newSprite = Resources.Load("Movie/picture" + counter.ToString("0000"), typeof(Sprite)) as Sprite; return newSprite; } At the beginning, the movie play smoothly, but after 10 seconds or so the movie starting to lag. I try to unload the resource every 2 seconds using `Resources.UnloadUnusedAssets();` but the problem still exist. Here is my full code for this. using UnityEngine; using System.Collections; public class CPlayButton : MonoBehaviour { private const int FPS = 24; private const int UNLOAD_TIME = 2; public SpriteRenderer movieTexture; private float SPF = 1f / FPS; private float UNLOAD_FRAME = 2 * FPS; private float timeCounter = 0; private int counter = 0; private int unloadCounter = 0; private bool isPlaying = false; // Use this for initialization void Start () { timeCounter = SPF; } // Update is called once per frame void FixedUpdate () { if (isPlaying) { if(timeCounter >= SPF){ counter++; movieTexture.sprite = GetFrame(); timeCounter = timeCounter - SPF; if(unloadCounter >= UNLOAD_FRAME){ Resources.UnloadUnusedAssets(); unloadCounter = 0; }else{ unloadCounter++; } }else{ timeCounter += Time.fixedDeltaTime; } } } Sprite GetFrame(){ Sprite newSprite = Resources.Load("Movie/picture" + counter.ToString("0000"), typeof(Sprite)) as Sprite; return newSprite; } void OnMouseDown(){ isPlaying = true; } } Can somebody help me about this problem? Or anybody know a better way of doing this?
Viewing all 85 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>