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

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?

Memory crash when calling Resources.UnloadUnusedAssets on Android

$
0
0
I have a memory crash when calling Resources.UnloadUnusedAssets on Android (using Unity 5.1.1 but in previous versions as well). The app just closes without any error message. The game shows photo's taken by other players so the player can like or dislike them. So this is the general flow, which is repeated: - load a texture: byte[] fileData = File.ReadAllBytes(filePath); Texture2D tex = new Texture2D(2, 2); tex.LoadImage(fileData); - show the texture on screen (using tk2dSpriteFromTexture of the 2D Toolkit plugin) - destroy the texture: UnityEngine.Texture2D.Destroy (tex); - call Resources.UnloadUnusedAssets and GC.Collect(): protected static IEnumerator DoMemoryCleanupCoroutine(Action callback) { yield return Resources.UnloadUnusedAssets(); yield return null; GC.Collect(); yield return null; if(callback != null) { callback(); } } After executing this 100-120 times, the app crashes when calling Resources.UnloadUnusedAssets. The crash will not happen randomly: if I do the same flow for the same amount of times on multiple devices they will all crash at the same moment. I have attached the profiler and added debug logging to track the memory usage, and there seems no increase or anything strange with that. So it doesn't seem to be a memory leak. I've also tried to create a texture pool so the Texture2D object is kept in memory and not recreated every time, but this does not seem to have any influence. It seems that there is a bug in Resources.UnloadUnusedAssets that makes it crash after calling a certain amount of times on Android... On iOS this does not happen. Any idea to solve this?

Does Unloadunusedassets unload unused assets loaded from Assetbundles?

$
0
0
Or, do those assets behave inconsistently with assets loaded via Resources.load and will stick around in memory even if they are not referenced anywhere? Alternatively, is there any way to unload assets individually that were loaded from a bundle?

[AssetBundles] - Why is my assetbundle.unload not unloading assets and therefore cannot loadfromcacheordownload again ?

$
0
0
Hi all, I am looking for some urgent advice/help regarding asset bundle LoadFromCacheOrDownload. UnloadAssetBundle is called on a button click in the UI. loadedAssetBundle is a member variable of class that has the functions. The following are the steps I take : 1. LoadFromCacheOrDownload(URL, 0) <- Get a WWW download with assetbundle from the web. 2. The above is successfull the first time. I check the IsVersionCached -> Returns TRUE. 3. Call Unload(false) on the asset bundle then destroy the object. 4. Try LoadFromCacheOrDownload(URL, 0) again with the same asset bundle. 5. Get the error -> Cannot load cached AssetBundle. A file of the same name is already loaded from another AssetBundle. See code below : private AssetBundle loadedAssetBundle; public IEnumerator DownloadAtURL(string assetName, string URL) { Debug.Log("PRE ASSET CACHED = " + Caching.IsVersionCached(assetName, 0)); Debug.Log("Downloading using -> WWW.LoadFromCacheOrDownLoad"); var www = WWW.LoadFromCacheOrDownload(URL, 0); yield return www; if(!string.IsNullOrEmpty(www.error)) { Debug.Log(www.error); yield return null; } Debug.Log("Finished downloading assetbundle"); Debug.Log("POST ASSET CACHED = " + Caching.IsVersionCached(assetName, 0)); loadedAssetBundle = www.assetBundle; } public void LoadAssetBundle() { Debug.Log("Loading all assets for bundle " + loadedAssetBundle.name); loadedAssetBundle.LoadAllAssets(); } public void UnloadAssetBundle() { Debug.Log("Unloading asset bundle " + loadedAssetBundle.name); loadedAssetBundle.Unload(true); Destroy(loadedAssetBundle); } See output below : Download Asset POST : https://55AE.playfabapi.com/Client/GetContentDownloadUrl Get content download URL for asset : 1/Windows/Windows result : https://cdn.playfab.com/55ae/etc/1/Windows/Windows?Expires=1438065963&Signature=oJa3DBfiDyRyE2hHix~Wpm1VqLrfoBzLTvlbTlf2RjPGtcwVAJj1y6ms9gp102GLAd7FAT2d-VCpSFKRAXLUPD04tor4j7znLl7EWQqi6TgEyBeLwBp3XY8D69S8gD4EJFH3V54hUVNZmk0nRCKBp4pJqnph4y4-DcChuCiIx0U_&Key-Pair-Id=APKAIOVJ4VBNZZU4TTQA Downloading 1/Windows/Windows from https://cdn.playfab.com/55ae/etc/1/Windows/Windows?Expires=1438065963&Signature=oJa3DBfiDyRyE2hHix~Wpm1VqLrfoBzLTvlbTlf2RjPGtcwVAJj1y6ms9gp102GLAd7FAT2d-VCpSFKRAXLUPD04tor4j7znLl7EWQqi6TgEyBeLwBp3XY8D69S8gD4EJFH3V54hUVNZmk0nRCKBp4pJqnph4y4-DcChuCiIx0U_&Key-Pair-Id=APKAIOVJ4VBNZZU4TTQA PRE ASSET CACHED = False Downloading using -> WWW.LoadFromCacheOrDownLoad starting www download: https://cdn.playfab.com/55ae/etc/1/Windows/Windows?Expires=1438065963&Signature=oJa3DBfiDyRyE2hHix~Wpm1VqLrfoBzLTvlbTlf2RjPGtcwVAJj1y6ms9gp102GLAd7FAT2d-VCpSFKRAXLUPD04tor4j7znLl7EWQqi6TgEyBeLwBp3XY8D69S8gD4EJFH3V54hUVNZmk0nRCKBp4pJqnph4y4-DcChuCiIx0U_&Key-Pair-Id=APKAIOVJ4VBNZZU4TTQA https://cdn.playfab.com/55ae/etc/1/Windows/Windows?Expires=1438065963&Signature=oJa3DBfiDyRyE2hHix~Wpm1VqLrfoBzLTvlbTlf2RjPGtcwVAJj1y6ms9gp102GLAd7FAT2d-VCpSFKRAXLUPD04tor4j7znLl7EWQqi6TgEyBeLwBp3XY8D69S8gD4EJFH3V54hUVNZmk0nRCKBp4pJqnph4y4-DcChuCiIx0U_&Key-Pair-Id=APKAIOVJ4VBNZZU4TTQA cached to C:/Users/Peter/AppData/LocalLow/Unity/WebPlayer/Cache/InfinityPlusTwo_puzzleverse/26d9c28d789c254f71ea99a3463b99a7ccc2f4fa ----- Total AssetImport time: 0.065631s, AssetImport time: 0.000000s, Asset hashing: 0.000000s [0 B, 0.000000 mb/s] loading from cache: https://cdn.playfab.com/55ae/etc/1/Windows/Windows?Expires=1438065963&Signature=oJa3DBfiDyRyE2hHix~Wpm1VqLrfoBzLTvlbTlf2RjPGtcwVAJj1y6ms9gp102GLAd7FAT2d-VCpSFKRAXLUPD04tor4j7znLl7EWQqi6TgEyBeLwBp3XY8D69S8gD4EJFH3V54hUVNZmk0nRCKBp4pJqnph4y4-DcChuCiIx0U_&Key-Pair-Id=APKAIOVJ4VBNZZU4TTQA Finished downloading assetbundle POST ASSET CACHED = True Unloading asset bundle Download Asset POST : https://55AE.playfabapi.com/Client/GetContentDownloadUrl Get content download URL for asset : 1/Windows/Windows result : https://cdn.playfab.com/55ae/etc/1/Windows/Windows?Expires=1438065979&Signature=eLuGatsAj0-yGDjltOWYIQjBf~4oNtGFlvOcXhacjt0InZjLotfyWPAHAWW64j3UH06sTYfeC9OGmmOjTD~WkkYSLgu5qpLtad6e~DF-cYj3jiK~fblZMEKsTAqhlb3m8~ZnaHqfsFS9~PGjoipUTNHvMy0Yh0JKYwwpa~N3B0Y_&Key-Pair-Id=APKAIOVJ4VBNZZU4TTQA Downloading 1/Windows/Windows from https://cdn.playfab.com/55ae/etc/1/Windows/Windows?Expires=1438065979&Signature=eLuGatsAj0-yGDjltOWYIQjBf~4oNtGFlvOcXhacjt0InZjLotfyWPAHAWW64j3UH06sTYfeC9OGmmOjTD~WkkYSLgu5qpLtad6e~DF-cYj3jiK~fblZMEKsTAqhlb3m8~ZnaHqfsFS9~PGjoipUTNHvMy0Yh0JKYwwpa~N3B0Y_&Key-Pair-Id=APKAIOVJ4VBNZZU4TTQA PRE ASSET CACHED = True Downloading using -> WWW.LoadFromCacheOrDownLoad You are trying to load data from a www stream which had the following error when downloading. Cannot load cached AssetBundle. A file of the same name is already loaded from another AssetBundle. UnityEngine.WWW:get_assetBundle() [C:/buildslave/unity/build/Runtime/Misc/WWWCached.cpp line 265] (Filename: Assets/sdk/scripts/TestBedController_Dev.cs Line: 357) WWWCached data can only be accessed using the assetBundle property! WWWCached data can only be accessed using the assetBundle property! WWWCached data can only be accessed using the assetBundle property! WWWCached data can only be accessed using the assetBundle property! You are trying to load data from a www stream which had the following error when downloading. Cannot load cached AssetBundle. A file of the same name is already loaded from another AssetBundle. WWWCached data can only be accessed using the assetBundle property! WWWCached data can only be accessed using the assetBundle property! WWWCached data can only be accessed using the assetBundle property! Cannot load cached AssetBundle. A file of the same name is already loaded from another AssetBundle. Finished downloading assetbundle POST ASSET CACHED = True You are trying to load data from a www stream which had the following error when downloading. Cannot load cached AssetBundle. A file of the same name is already loaded from another AssetBundle. Any ideas why UNLOAD is not working ?! Seems like a bug in unity, not sure what else I can do here. Would be most appreciated and thanks in advance.

UnloadUnusedAssets - Causing Loss of Used Assets

$
0
0
Hello, Has anyone heard of this happening? When I call 'UnloadUnusedAssets' my app gets odd affect of textures disappearing, or being replaced completely. The app is a Cartoon Comic book, each page is a prefab that is dynamically loaded via Resource.LoadAsync, and then unloaded when the Page isn't being viewed anymore. The idea for this method is to reduce memory load as each page contains high quality textures which will crash the app if all are loaded in at startup. (for iOS). This is how I load a page in: var request : ResourceRequest = Resources.LoadAsync( GetPrefabName(lindex) ); while(request.isDone == false) yield; loadedPrefab = Instantiate(request.asset) as GameObject; So, the problem is, when I try and unload a page like so: Destroy(scene); yield WaitForEndOfFrame(); Resources.UnloadUnusedAssets(); System.GC.Collect(); It works fine, the system memory is decreased. But a couple of textures throughout the app are now missing, or have been completely replaced by a random texture, not only that but my Texture Renders will sometimes 'untarget' themselves from the page camera (it's what I use to render my comic page). Whats odd though, is that these 'missing' textures are within other dynamically loaded pages (prefabs), meaning the app has to load in everything onto memory anyway, yet the texture may still be incorrect. Can anyone explain this please? Thanks.

Issues with unloading textures and atlases

$
0
0
We seem to be having some issues with Unity not unloading textures (and other assets) that are no longer in use. During the development of a previous project in Unity 4.x, I created a tool that reports the amount of textures, meshes, materials, sounds, etc., using the Resources.FindObjectsOfTypeAll method. This tool seemed to work nicely in Unity 4 and helped us track down memory leaks in our previous project. I hope this method still works as it did back then? We are now in Unity 5.2.4. To explain in a bit more detail what is going on, our game loads new scenes by first fading out, showing a load screen and then 'behind the curtains' load an empty scene, in which we call Resources.UnloadUnusedAssets () and System.GC.Collect (). After this the game loads the actual scene that was requested. The problem is that it seems unused assets are not being unloaded in this process. We have a main menu scene with some buildings in it, but upon loading any of the actual gameplay scenes, the meshes and textures used on the buildings in the main menu scene are still loaded, at least according to FindObjectsOfTypeAll. Same issue when we return to the main menu after having been in any of the gameplay scenes: A lot of the assets used in the gameplay scene are still reported as being loaded. I know that if just one object somewhere references a prefab or is linked to a texture or anything like that, the asset will remain in memory, but I can't find anything in our gameplay scenes that should be referencing assets from our main menu. It might be that we are, but I just can't find it, so I'd like to confirm that this is not a known issue with Unity 5.x. Another thing is that according to the tool I made, it seems that various texture atlases, created with Unity's SpritePacker, are loaded multiple times. My tool looks through the loaded assets and counts assets with the same name and some of the sprite atlases (textures starting with 'SpriteAtlasTexture') seem to be appearing multiple times in the list. Is there a reason for that? It also seem to load texture atlases that aren't used.

Profiling and clearing memory

$
0
0
I am currently profiling my game and trying to do some memory management. I have a lot of objects in my game that are memory pooled during the loading of the level. When I don't need objects they are set to inactive and upon reloading i activate all of them back again. This also minimizes the loading time for my game. I see that memory is not being freed for obvious reasons, as I am not destroying any objects. So I want to know if I should destroy unwanted objects or calling Resources.UnloadUnusedAssets after deactivating objects will unload all the textures and other memory used by them? Any help is appreciated. Thanks.

Unloading a prefab using Resources.UnloadUnusedAssets.

$
0
0
When I try and unload a prefab loaded using the Resources.Load(), I get an error saying gameobjects cannot be unloaded using Resources.UnloadAsset(). So the other way to do it was destory the instances of the loaded prefab in the scene and then call Resources.UnloadUnusedAssets. But when I do this, the instances are destroyed but the prefab is not unloaded and hence even the texture it access stays in memory. Only when I call Destroy on the prefab itself and then call Resources.UnloadUnusedAssets do I see the prefab and texture unloaded from memory. But then I get an error stating "Destroying assets is not permitted to avoid data loss. If you really want to remove an asset use DestroyImmediate (theObject, true);". Here is my code example: private GameObject prefab; private GameObject instance; void loadGameobject() { prefab = Resources.Load("test/buildings", typeof(GameObject)) as GameObject; instance = (GameObject)Instantiate(prefab); } void unloadGameobject() { Destroy(instance); Destroy(prefab); // this line gives me error, destroying asset is not permitted Resources.UnloadUnusedAssets(); } Let me know what I am doing wrong, and how do you successfully unload prefabs.
Viewing all 85 articles
Browse latest View live


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