- Home /
Xcode > Unity SendMessage
Hi, in my Unity iOS app I want to catch the memory lack to avoid the "Message from debugger: Terminated due to memory issue" and consequent crash.
I followed this thread: http://answers.unity3d.com/questions/291788/is-there-a-way-to-tell-in-unity-ios-when-ondidrece.html
In Unity I added a GameObject called "MemoryManagerObj"; on it I attached the following cs script:
using UnityEngine;
public class MemoryManager : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void LackOfMemory(string MemMsg) {
Debug.Log ("LACK OF MEMORY!!!");
}
}
In folder Plugins/iOS I added the following iOSMemoryController.mm:
#import "UnityAppController.h"
@interface iOSMemoryManager : UnityAppController {}
@end
@implementation iOSMemoryManager
- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application {
printf_console("WARNING MY OWN APP CONTROLLER -> applicationDidReceiveMemoryWarning()\n");
UnityPlayer.UnitySendMessage("MemoryManagerObj", "LackOfMemory", "Message");
}
@end
IMPL_APP_CONTROLLER_SUBCLASS(iOSMemoryManager)
I builded the Unity project and open in Xcode. Now when there is a memory issue I've this message:
WARNING MY OWN APP CONTROLLER -> applicationDidReceiveMemoryWarning() SendMessage: object MemoryManagerObj not found! Message from debugger: Terminated due to memory issue
though the GameObject named MemoryManagerObj exists.
Where I'm wrong?
Thank you!
Answer by devilishgames · Sep 02, 2017 at 09:14 AM
Hi @Giusort, by taking a quick look at the code you copied, your gameobject is not called "MemoryManagerObj" but "MemoryManager", you should also delete "UnityPlayer" from "UnityPlayer.UnitySendMessage".
So your code would stay:
#import "UnityAppController.h"
@interface iOSMemoryManager : UnityAppController {}
@end
@implementation iOSMemoryManager
- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application {
printf_console("WARNING MY OWN APP CONTROLLER -> applicationDidReceiveMemoryWarning()\n");
UnitySendMessage("MemoryManager", "LackOfMemory", "Message");
}
@end
IMPL_APP_CONTROLLER_SUBCLASS(iOSMemoryManager)
Your answer
Follow this Question
Related Questions
Message sender...how to know who send the message 1 Answer
random limitation memory game 0 Answers
Does Unity load in memory textures that are target of public variables ? (iOS) 1 Answer
iOS - SystemInfo : Appropriate use? 0 Answers
good resource about conserving memory when multiple levels share resources? 0 Answers