Hi.
I have been reading about optimisation and im looking for guides on the best approach for my query. I have a grid made up of cubes. When the player hits move they move up/left/down/right to the next cube.
Each cube has a trigger and various actions which happen. Due to the scale of my game i have loads of scripts running when i dont need to unless the player is close by. This will save alot on performance for mobile.
I was wondering on hows others handle script enabling for mobile. I imagine it like how LOD works (diagram attached). The pink represents the character and the dotted line is the trigger area. The second image shows which scripts are active (grey boxes).
Also i cant have my objects instantiate as i need to place them by hand in the editor due to the strategy of my game. it would be a nightmare to work out how to object pool these blocks.
Start the game with every object SetActive to false. When the game starts just active the cubes within the range you decide is good. Each time he moves, you figure out which ones he moved out of range of , and turn them off, and turn on new ones. This should be pretty quick since everything is turned off and your just dealing with a small subset of your GOs
One strategy
Create a List currentlyOn that are currently on.
Whenever you character moves, create a new List shouldBeOn that should be on.
If any GO is in currentlyOn and NOT in shouldbeOn turn it off
If any GO is in shouldBeOn and isn’t in currnetlyOn, turn it on.
ok that sounds ok, i understand what you mean and that every cube starts off with a SetActive to false, then am i right in saying that once ive detected all of the objects which are in range and sent an event to activate them. i would need rigidbody colliders (kinematic enabled) on each cube so the players trigger can pick them up?
You can just use a sphere trigger, when collision happens with the trigger call the script(s) attached to the cubes. Trigger events are only called on collisions making them efficient.
Trigger events can still make calls to disabled monobehavoiurs as well.
I didnt know that they could still be sent when disabled, thats cool. So for all my scripts (some cubes have child objects with scripts on them) would i need to add a SetActive on all of the child scripts too? or would the parent script be good enough to add it too? as i wanted one script on every parent cube to do this action, the child scripts do other stuff.
What im trying to ask is it a case of rewriting all scripts OnStart and adding SetActive to disable them?