2

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

Erik Partila
  • 63
  • 1
  • 6
  • Does this answer your question? [SetActive() can only be called from the main thread](https://stackoverflow.com/questions/53916533/setactive-can-only-be-called-from-the-main-thread) – Drag and Drop Sep 23 '22 at 16:21

2 Answers2

3

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

Erik Partila
  • 63
  • 1
  • 6
0

In my understanding, when Unity is processing graphic rebuild (which is behind Update() and StartCoroutine), you are not allowed to modify UI elements (such as calling SetActive()).

So you should do these operations after a while. You can use StartCoroutine ,which guarantees to run your code at the next frame before the graphic rebuild.But you have to write your code after the yield keyword (because the codes before yield keyword will run immediately in this frame, conflicting with the graphic rebuild).

vainquit
  • 491
  • 6
  • 13