Unloading X unused Assets to reduce memory usage - How to disable?

I’ve seen a few other posts similiar to this, but I figured I’d put out my exact details.
Basically, it seems Unity is cleaning up a GameObject I need to stick around!

Here is the log:

Unloading 1 unused Assets to reduce memory usage. Loaded Objects now: 242.
Unloading 1 Unused Serialized files (Serialized files now loaded: 0 / Dirty serialized files: 0)
[Switching to thread 11523]
Program received signal:  “EXC_BAD_ACCESS”.
Current language:  auto; currently c++
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
Xcode could not locate source file: RakNetTypes.h (line: 320)

I have a singleton manager class that does not inherit from anything.
I have the following in the singleton:

// Declared
private static GameObject _FBPluginObject;
...
// Later...
_FBPluginObject = new GameObject();	
_FBPluginObject.name = "iOS_FBCallbacks";
_FBPluginObject.AddComponent("iOS_FBCallbacks")

The OnDisable() for the iOS_FBCallbacks class (which is a MonoBehavior) is getting called when the above.
Is there any way to mark a game object as “do not delete?” I already called DontDestroyOnLoad(this) in it’s Awake() function…

Thanks for any ideas!

1 Like

I guess your object is being deleted because you have some destroying code on the OnDisable class. Maybe you could add some conditional code on it to avoid it being destroyed at its initialization. You could also build a Prefab and instantiate it with GameObject.Instantiate() function.

I do not do anything in the OnDisable() that should destroy anything.
I tried the prefab solution and get the same behaivor.

Here is the Awake() and OnDisable()

It always states “Set Inactive” in the console.

Probably you should write DontDestroyOnLoad(this.gameobject) instead of DontDestroyOnLoad(this).

i have the exact same problem how did u fix?

anybody find a fix for this

1 Like

This is really annoying on a headless server…

Did anyone find a solution for this?

1 Like

Found a solution based from this thread:

You need to follow the "Simple checklist for making your distribution as small as possible" from this manual Unity - Manual: Optimizing the size of the built iOS Player

I hope this helps you.

1 Like

Hello @charmcrescini
First I apologize for bothering you and taking up your time.
It’s clear to me that it’s been a long time since I posted this issue, but I’m going through the same thing now.
I have reviewed your link, but I am not sure what I should do to solve it

After so much time has passed,
Do you remember how I solved this problem ?
I hope you can help me, I am working on this problem for 3 days
Thanks

1 Like

하하이용