Search code examples
c#unity-game-engineruntime-errorgame-developmentgameobject

Unity Trying to add image for graphic rebuild while we are already inside a graphic rebuild loop. This is not supported


I am working on a game in Unity, but recently I came across this unexplainable error, that pops up when I try to edit components of a GO child..

item.transform.GetChild(0).GetComponent<SVGImage>().sprite = script.GetFlipperPreviewSpriteById(myFlippers[i].Id);

item.transform.GetChild(1).GetComponent<Text>().text =  myFlippers[i].Id+" flipper";

and I get this error message..

2022.05.03 21:52:48.749 22693 27192 Error Unity Trying to add IMG_imageItem (Unity.VectorGraphics.SVGImage) for graphic rebuild while we are already inside a graphic rebuild loop. This is not supported. 

I started to get this error after I implemented Firebase into my project and I can't really move on. I can't find any article talking about this so I hope I can get at least some answers :) Thanks in advance !

Unity version 2019.4.36f1


Solution

  • after 5 pages of google and a bit of luck I found this post talking about exactly my problem, basically you can update UI only on main thread, so when you work with async functions such as firebase, you need to make functions that edit your UI to run on main thread

    SetActive() can only be called from the main thread