I’m making a small city where the player can break things (like GTA and stuffs…) so, i have an script on the windows of the houses. It is an code that defines how the glass is broken, but there are many houses which means the same code on every window. so my questions are.
Is there a way to make this code more optimazed?
It does not matters the same copy of the script on every windows on every house?
ScriptableObject maybe?
I read about “ScriptableObjects” and maybe that is an optimazed way to do it for mobiles. Of course i do not know how to do it in that way but youtube can solve that
If my question is too dumb for you keep in mind that i’m a noob programmer (in fact, i’m a 3d artist and graphic designer)
Also if you are a “google it” person, please do not waste your precious time here.
Only in the sense that you’ll have a lot of copies of it running, so if you for example have these running an Update function, that will cause some overhead per object. (This is always true, and it’s a good habit to remove the Update() function on anything you have a lot of copies of, unless it’s really needed)
But what’s almost certain to have more impact will be other parts of those windows, and that will depend a lot on the details of how you implement the broken glass.
Will you destroy the main object and spawn a particle effect (easiest, by far, but also the least cool looking effect)? An object with an animation Destroy it and spawn a bunch of physics objects for accurate simulation? Will you be creating the fragments or are you looking to procedurally generate crack patterns for each window?
No, “ScriptableObjects” are pretty much just a way to store your own custom data in asset files, they would be basically unrelated to something like this.
The code in the object “GlassWindow” is just a trigger.
I’m not spawning particles or physics objects. I have a prebab with 2 objects. One of them is 1 polgon which is the unbroken glass and the other is the broken glass with animation that will be enable on the trigger.
Ok i understand, it is not what i thought.
So i guess it does not matter that much if i have that code (the OnTriggerEnter stuffs) on the prefab, it does not have any “Update” function.
Ideally the code of the windows is only called when there is a collision, so they woudln’t check every frame, if that’s verify, it shouldn’t have any impact on performance, all the optimization are done by the collision engine, then it dispatch event to the concerned objects.