- Home /
a function is working on editor but not working on android divice
Hi I'm using unity 5.1.1 and my 2D game is fully work's on editor but one of my function is not working in android and it just skip other onClick jobs on my UI button. this button is doing several things but i checked when it calls that function, jobs after that are skipping and the function it self is not doing anything. my function is :
public void InventoryUpdate()
{
i = 0;
foreach(Transform child in transform)
{
Destroy (child.gameObject);
}
foreach(var key in myDicObjects)
{
string keyname = key.Key;
int keyNumb = key.Value;
if (keyNumb != 0)
{
inDicObj = GameObject.FindGameObjectWithTag (keyname);
gameObjectsDic[keyname] = inDicObj;
//create a new item, name it, and set the parent
newItem = Instantiate(itemPrefab) as GameObject;
newItem.name = keyname + " item at (" + i + ")";
newItem.transform.SetParent(gameObject.transform);
//set number of obj
newItemNumb = newItem.GetComponentInChildren<Text>();
//move and size the new item
rectTransform = newItem.GetComponent<RectTransform>();
rectTransform.localScale = new Vector3(1,1,1);
containerTemp.x = myDicObjects.Count * 100;
containerTemp.y = containerRectTransform.sizeDelta.y;
containerRectTransform.sizeDelta = containerTemp;
// position inventory stuff
temp.x = ((-containerRectTransform.sizeDelta.x / 2)+50)+(i*100);
temp.y = (containerRectTransform.sizeDelta.y / 5);
rectTransform.offsetMin = rectTransform.offsetMax = temp;
rectTransform.sizeDelta = new Vector2(100,100);
//set itemPrefab values
prefabSprite = gameObjectsDic[keyname].gameObject.GetComponent<SpriteRenderer>();
itemImage = newItem.transform.Find("Image").GetComponent<Image>();
itemImage.sprite = prefabSprite.sprite;
InventoryManager invenManager = newItem.gameObject.GetComponent<InventoryManager>();
ObjController objController = gameObjectsDic[keyname].gameObject.GetComponent<ObjController>();
invenManager.objValue = objController.objValue;
invenManager.sliderTag = objController.sliderTag;
invenManager.objXp = objController.xpValue;
i++;
newItemNumb.text = keyNumb.ToString();
}
}
}
any Idia??!!!!
Have you set up a number of debug logs throughout to see if each step of the code is calling? It can help you identify if one line is having an issue (certain things in Unity wont work on Android and/or iOS).
Additionally, do yourself a favour and convert those foreach loops into for loops. foreach loops can cause a memory leak with Unity and you don't want that :)
Can you Explain what part of you function is particularly not Working ..
Answer by H-Rat · Aug 25, 2015 at 08:22 PM
i changed the second dictionary to a list and i can loop throw it now on both editor and android and it solved my problem, but I'm steel wondering why i couldn't use dictionary.I debugged it and find out when ever i tried too loop over a dictionary it 's not working on android device and dictionary.count was have same problem. Is it a BUG??? because it's working on editor without any error...