I am making object pool to optimizing my project. My project has involved object appearence change and I planned to using object pool to recycle the old appearence while the new appearence is generated. However, I found it is tricky to pass the scripts attached to the old appearence into the new one.
Currently, I had two solutions. One is to create an empty object as the parent for both appearence and attach the scripts into the parent object. The other is I just pass the param between two object manually.
However, I am not satisfied with the previous two solutions. Does anyone has better ideas ?
Yes, that is my solution two, passing param manually. While I wish to found a way that can make this process as concise as GameObject.AddComponent<>(). Any clue?
As spiney199 has pointed out you might be able to encapsulate the data into an object but the answer requires a whole lot more information. I suspect there are lots of alternatives dependent upon what the changes are. Is this something a factory class could build and hand back to you?
Right, but did you understand the ‘encapsulate’ part? Once you have everything neatly wrapped into one object you can easily do something like .ApplyAppearance(AppearanceData data);.
This of course will likely involve a decent refactor to represent this information in a more plain C# object manner.
That said, don’t optimise if you don’t have a performance issue.
Really greatful for your answer. It gives me a clearer view of the object pool usage. And yes, I will still using object pool in this part cause I need to change the apprearance as frequent as creating bullet and the info related to those apprearance is limited.