Hi Guys,
Im trying to create the sprite animation game i have about 300+ images for one character which are distributed between 12 different animations. The image count for the animations differs from animation to animation. The min number of images for a animations is 20 frames/png. and the max image sequence for an animation is 69 frames. The Images resolutions are different ranging from 512x512 to 256x256 (Note the width height remains same for the same animation)
Since there are too may images and we cannot load all the images at the same time im trying to load them using prefabs and destroy the prefabs when the animation is completed.
The Actual scene is just having one Camera and one script attached to it called AniamtionHandeler.cs. This Script is creating an clone of the prefab object which is attached to it as public. when the button is pressed. The prefab is having a common script attached to it, which plays the animation and when the animation is completed its getting destroyed.
Now since im using the prefabs im expecting the images to load runtime as this will save loads of memory. but I think this is not happening at all. im using DetectLeaks.cs which is available on the wiki. im attaching the images of the output.
One more thing which i have noticed now is that the application is working well in 3GS and its not loading (Crash “Low Memory” in crash log) on other devices its obviously due to the improved hardware.
Can anyone help me with the problem i have tried every possible solution which i can think of.
[b]__AnimationHandler.cs__[/b]
public GameObject NormalObj;//Taking the Prefab Object : this is nothing but a GUI Texture used For showing the Aniamtion
public GameObject FireAniObj; // Taking the Prefab Object : this is nothing but a GUI Texture used For showing the Aniamtion
Object AnimationPrefabObj;
Object DefaultObject;
void OnGUI () {
GUILayout.Label("Actual Memory "+ SystemInfo.graphicsMemorySize);
GUILayout.Label("All " + FindObjectsOfTypeAll(typeof(UnityEngine.Object)).Length);
GUILayout.Label("Textures " + FindObjectsOfTypeAll(typeof(Texture)).Length);
GUILayout.Label("AudioClips " + FindObjectsOfTypeAll(typeof(AudioClip)).Length);
GUILayout.Label("Meshes " + FindObjectsOfTypeAll(typeof(Mesh)).Length);
GUILayout.Label("Materials " + FindObjectsOfTypeAll(typeof(Material)).Length);
GUILayout.Label("GameObjects " + FindObjectsOfTypeAll(typeof(GameObject)).Length);
GUILayout.Label("Components " + FindObjectsOfTypeAll(typeof(Component)).Length);
Rect MyRect = new Rect( 405, 5, 70, 35);
if ( GUI.Button(MyRect, "Slam" ) ){ // Creating the Button
if ( MyClone == null) { // if the clone is already existing than dont clone it
Vector3 TempPos = new Vector3(0, 0, 0); // Setting the Position
MyClone = Instantiate(SlamAniObj, TempPos, Quaternion.identity);// Creating the clone of the Prafab
DestroyImmediate (MyBasicClone); // Deleting the Prefab Object
}
}
// Update is called once per frame
void Update () {
if ( MyClone == null) {
if(MyBasicClone == null) {
Vector3 TempPos = new Vector3(0.5f, 0.5f, 0); // Setting the Position
MyBasicClone = Instantiate(NormalObj, TempPos, Quaternion.identity);// Creating the clone of the Prafab
}
}
}
The Above code is acting as my Main Class which controls the Creation/cloning of prefabs when no other prefab is already created/cloned.
[b]__PrefabAnimation.cs__[/b]
public Texture[] AnimationImages;//Array of images approx 64 images for the Animation of 512x512 / 256x256 / 512x256 / 256x512
void Update () {
if ( m_fMyTimer < Time.time ) { // Checking the Timer for next change of image
if ( m_iCount < AnimationImages.Length-1 ){// Checking the length of the Image array if current count is less thean the size of the array than changing the image
guiTexture.texture = AnimationImages[m_iCount];//Loading the next images in the array
m_fMyTimer = Time.time + m_fWaitTime;// Updating the timer for next change
m_iCount++;//Setting the Next Index for loading the new img
}
else{// If we have completed the aniamtion than deleating the Game object from the scene (Note this is a prefab object created on the fly from another Script )
Destroy(gameObject);// Deleting the Prefab object
}
}
}// End of Update
Image 1: This is when the Prefabs Is cloned (You can see the compound count getting set to 34)
Image 2: This is when the Prefabs clone object is deleted (You can see the compound count getting set to 33)
Note : This are the actual reading from the device (iphone 3GS)``

