UnityCleanup() (450501)

I need to completly unload Unity - so I am using UnityCleanup()…
But how to unregister all mono modules? (cause I would like to start up unity from scratch again)…

Without unregister I got crash on second startup - may be some other method must be called?

Thanks!

You are doing that in the Unity Editor? And is there such thing as UnityCleanup() function. I don’t see it in the scripting reference. What are you trying to do then?

Just write a function that does the same the register modules function does (its present in the sources) in reverse.

But be aware that unity is not exactly layed out at the usage you do there but as monolithic app that goes up and down along the engine so you might find more or less complex problems you might not be able to work around. Normally when interacting with native stuff its done the other way round: unity is always alive and you overlay a view controller, pausing unity along that so it does not run during the overlay

Dreamora - what I need is completly stop Unity (not pause), cleanup it and maybe unregister mono modules… Is it possible?

Now I have empty level in Unity and it takes about 40mb on iPhone4…

And I would like completly stop Unity…
Could you help me please? Just what should I do in AppController.mm…

What do you mean register in the reverse direction? (unregister?)

And after stop I must restart Unity (inside application - without crashing or exit)

Is it possible to restart Unity or due to bag in Mono (I try to restart - but mono crashes I see in log) or its not possible now?

Looks like this thread is a few months old, but I was wondering if you figured out how to clean up Unity properly.

I’m attempting something similar, trying to load/unload Unity within an Obj C ios app and it starts/exits fine until I try to restart, then crashes with what looks like a mono error in the console:

→ applicationDidFinishLaunching()
Mono path[0] = ‘/var/mobile/Applications/E5B32483-30C1-4596-9247-BA1DA0A0EC7C/UnityTester.app/Data/Managed’

  • Assertion at critical-sections.c:61, condition `ret == 0’ not met

Dreamora posted about reversing mono module registration, however I can’t find any way to unregister these modules (as opposed to mono_aot_register_module). I’m assuming there must be a mono_aot_destroy_module or some similar function but have not found anything in the mono man page.

Has anyone successfully done this, or have any ideas?

Thanks

I have the same error - situation is not changed.
I submited a bug one year ago - but no progress…
Maybe someone unity developer could comment?

PLEASE! HELP!

How to restart unity completly under iOS - I need to use several Unity projects in one iOS application.
I need shutdown - but got the same as above assertion in critical section!!!

HELP :slight_smile:

I spent a good while digging to try and do this same thing and I do not believe it is possible. The UnityCleanup function calls into the compiled Unity closed source Unity library to do its work, and it does so in a way that does not reset up unity to be called and started again.

The only feasible way I think you could get this to work is to do something extremely hackey like watch all the memory that UnityStart registers, then on cleanup clear that memory explicitly, not relying on UnityCleanup(). But the possibilities of that working smoothly and reliably are not something I’d bank on for any serious work.

And now i am also here :slight_smile:

Mono path[0] = ‘/var/mobile/Applications/E5B32483-30C1-4596-9247-BA1DA0A0EC7C/UnityTester.app/Data/Managed’

  • Assertion at critical-sections.c:61, condition `ret == 0’ not met

Anyone got the solution???

@Hamdullahshah: Have you managed to solve your issue?

Me too!!
Got the error: * Assertion at critical-sections.c:61, condition `ret == 0’ not met
Is there some one got this solution?

It seems this post is too old and no solution for this issue.
I need to stop Unity and get back memory from unity and then continue to native app.
Can anyone help?

Does anyone have any luck successfully doing “load and unload Unity on demand within an iOS app”?
Any help/direction is much appreciated!

no, this isn’t how it’s supposed to work. Mono runtime is not meant to be treated as a module, but rather an additional layer on your app.

Shouldn’t this be reconsidered now, in 2018? A lot of people have already built apps and want to integrate Unity as a feature and not an entire app.

now in 2019, this problem still no answer…

Application.Quit

How to call this ‘Application.Quit’ in iOS?

https://docs.unity3d.com/ScriptReference/Application.Quit.html but notice the note

Unity as a Library feature introduced in 2019.3.a2+, it makes some unity integration scenarios possible or easier, might be worth to look at

I called it unloadapplication in a native app, but the memory is still high, how can I reduce the system.excutableanddlls.and
the API "unloadapplication"in unity document show it will reduce large memory and residue 110mb memory, how to do this