Recursive Loading of Assets in Scene When Launching Player

This is a quirky bug that I ran across today and was hoping that someone might have a clue as to where I should start troubleshooting. Prior to this bug, I had the Visual Studio IDE open and was cruising along. I had made some very minor changes to some MonoBehavior classes (i.e. adding a public property and adding newly created animation events’ methods for two animations I had just added the events to). When I went back to the Unity editor, waited for it to re-compile, and then launched the game/player from within the editor…something odd happened. It just kept loading and at first I thought it was going to crash, but then after about 30-40 seconds I decided to look at the task manager… the Unity editor was consuming close to 20GB of memory…and it was still growing…
I killed the Unity editor from the task manager and wondered over to the log files to see if I saw something telling…and noticed it appeared to be recursively loading the scene assets over and over and over again.

So, to make sure, I reloaded Unity with the same scene, started visual studio and attached to the Unity editor, and then placed some break points in several of my classes (MonoBehavior derived) at the Start method… and sure enough…it would call the Start method for each asset as if it was loading the scene normally and then it would repeat itself as if it was re-loading the same scene again… and repeat itself again…and so on…

So far, I have no code that does scene loading or the like… just a single scene and the assets…which a scene loading bug or the like is out of the question.

I tried clearing out the cache files and all of the typical things… I actually even tried to upgrade to 2020 but that presented a whole new set of issues that I am not ready to deal with and would like to finish up what I have currently.

What I am currently running is 2019.4.4f1 and have the URP package installed. I know for a fact my code base isn’t forcing this reloading of assets… so my question is:

What is a good place to start troubleshooting what might be corrupt and/or what could cause the editor to just continually reload the same GameObjects (that only have one instance in the scene) recursively?

I noticed from the documentation I can get the debug symbols to debug the editor… would this be a good place to start and if so is there a suggested “entry point” I should start from to see what the heck is causing this bug/issue? It is just kind of mind boggling because the changes I made prior to this behavior were very minor (the only thing I can guess is the Animation Events and associated callbacks I added but I have done that many times in the past few weeks and never ran across this)…I do have all of my assets backed up, but even restoring them, re-importing them, etc. the problem still persists…very quirky.

Anyone else run into this and if so any suggestions are welcome.
:slight_smile:

Here is an interesting update…after looking through a few things I remembered that I had added some code that instantiates a few copies of an AudioSource component in a specific GameObject during that same period and had just linked the AudioSource to a reference in another attached script component. This code simply makes 6 copies of the AudioSource (pooling) to be able to play spatial sounds around the player area when the player is hit.
It seems that either:
1.) I have instantiated too many AudioSource instances (is there really a limit to this? Surely not…) and it exposed some weird random recursive loading bug…not likely with the way Unity is built it has to be something else.
2.) Attaching the AudioSource Component to the same gameobject your are creating instances of the AudioSource is the culprit…yeah…that is the issue… >.<

My guess is #2 is the winner…as it would make sense that the instance of the AudioSource component would be based on the GameObject it is attached to…and if that very GameObject is instantiating more versions of the same AudioSource it would just recursively keep creating itself over and over… sigh

It is a silly bug that I believe is my personal “user error” in implementation and lack of sleep… so I am going to do the later before I add more quirky bugs to my project.

Either case, unless my reasoning behind selecting #2 as the primary reason my scene “seemed to be recursively reloading itself” is not accurate… please disregard the original post as I believe I solved my own issue.