- Home /
Which Implementation is Better? A Performance Question
Hello everyone, I'm looking for general input on which (if either) of my two current implementations below is superior (from a performance standpoint and from a "best practices" standpoint).
My Situation:
I've got a pooled decal system setup, and when a decal is needed it attaches itself to the object that needs the decal. The catch is, when these objects that need decals are destroyed/recycled, I need the decals to go back to a "default state" to be ready for further use. I have two main implementations that I have thought of so far:
A) Using Events:
-Here, a decal simply gets a reference to the objects unique ID. When that object is destroyed, it sends an event using its unique id as a parameter, and all decals check against it. If it is the same, the decals reset themselves.
-The pros to me are that it is very simple, but I'm concerned that with many decals (lets say 100) in the scene, it could cause performance spikes when every decal receives the event.
B) Object Record Keeping:
-Here, each object keeps a dictionary of how many decal scripts are on it. When the object is destroyed it first goes through this list, calling a reset method on each decal.
-The pros is that when an object is destroyed, only relevant decals are called. However, this creates a need for both objects to keep track of what decals they have (though that is easy enough), and for the decals to keep track of the status of themselves / the object they are going onto so they can add/remove themselves correctly (don't remove themselves from objects that they aren't on, don't add themselves to objects they are already on, etc).
Any ideas are appreciated, thank you for reading.
Answer by CodeMasterMike · Mar 24, 2015 at 01:16 PM
I would use the option B, because I find it better when each individual object takes care of itself, and keeps track of its own objects (decals in your case). And the performance will not suffer if you add more decals to the world during gameplay.
It is little more work to get the option B to work, but in terms of performance and possible future debugging/testing, it will certainly be worth it.
@Code$$anonymous$$aster$$anonymous$$ike :
Fair enough, that is what I will do.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Low Priority Methods In LateUpdate? 1 Answer
Multiple Cars not working 1 Answer
Why deactivating objects is so slow? 1 Answer
WorldToScreenPoint in Update/OnGUI: Bad Performance 1 Answer