I have 2000 rbs, what should fly around in the background buch collide with theTilemapCollider.
The FPS drops to 5FPS, when they are spawned.
How can I then those objects move and collige but not have a rb? (I believe that`s the bottleneck)
I also tried around with OnBecameVisible() but this never gets triggered, even when I pointed the sceneView away.
Hey there and welcome to the forum,
in general you already ask the correct question: Do you really need those 2000 rbs? But that question you will have to answer, as only you know what the goal of your project is and what exactly it is you want to do. In general 2000 RBs is a lot. This is way byond the normal usecase of Unity.
However there are still things you can do. For once there are the Physics settings. You can find them in your project settings. Changing some values there (e.g. the amount of solver iterations or the approach the solver takes) can give a performance boost (but mostly at the cost of collision accuracy and stability - so be careful here). Beforce you make any changes here read the Documentation!!.
Other then that you can read about general improvements of game performance with physics. For example mesh colliders have a way worse performance than primitive colliders like boxes or even better: Sphere/Circle colliders.
Apart from this you don not have to guess what the bottleneck is. Unity has a builtin Profiler which can tell you exactly where your performance is used up. given your description that you “spawn” the objects - assuming that you use
Instantiate here - yes that is expensive. You can work around high lag spikes by Instantiating objects over multiple frames with a Coroutine (for example during a loading screen).
Check the profiler results and try to optimize on the information you gain there.
As a last escape route check out Unities Entity Component System. With that 2000 RBs is a piece of cake but it is way more difficult to do anything and will require you to relearn everything that you know about how Unity works.