Hi! This is me again, with long hard-to-read posts :3
tl;dr: i’d like to be able to do either of this:
- increase maximum script components in the project settings
- being able to delete the script component from the object, as it only have init() function in itself.
I can’t really remove these scripts and combine them into one large script, because it will create a lot of ugly and tedious work for level designers and might leave some “hard-to-find” errors in the map.
I can do dynamic creating/deleting of large collections, but i’m afraid of the lag, so i’d rather avoid this solution for now.
Because our game has “technically-real-3d” view (check screenshot - trees are facing camera, tilemap is flat, we get real parallax and everything), we have to add some logic to map objects on init() function. Basically we have to rotate lots of objects on the map to face the camera angle when they are created. This angle might be changed and we can’t just set it in the editor, so we do it from the script in the init() call. After that, the script is basically not needed and could be deleted.
Obviously, we faced the “Could not create script component” problem quite fast, so we made a hack - not every object has a script on itself, but rather a collection with multiple objects controls them. For example we hawe this forest pack - a collection with collider, multiple trees sprites game objects (1-4 trees in each sprite for optimization) and a controller script, which knows the amount of tree sprites (passing total amount in the inspector, because we can’t have arrays, duh ). This limits us in creating more “diverse” visuals, but reduces the amount of scripts by a lot and solves it for custom manually created maps.
But then we tried to make a larger, procedurally generated maps and this problem appeared again. The map consists of large (~2 screens wide) manually constructed tiles, with the same collections in it. In addition, there are scripts like monster spawners, might be some more randomizers (put a box or a barrel in the specified spot, etc). Most of this scripts only have init() function and don’t (i hope) really use any CPU after that, so i’m fine with having too many scripts in the scene, but i can’t change scripts maximim amount in project settings.
Of course, i can do dynamic loading, having in memory only zone of 3x3 “large” tiles around the player and destroying other ones, but there is a chance there will be some lag when spawning 3 new tiles, which might be noticable by the player. And well, enabling/disabling looks like a better way to do that.
On the other hand, if i can delete the scripts - i can spread the map loading onto multiple frames, deleting all the init() scripts in the each frame, so i won’t reach the scripts limit, but i can’t do that right now.
Any suggestions for me?