- Home /
Performance and memory
I have a bunch of creeps on a map. I need to save their location in a list when they enter a trigger and remove them when they leave. I also have to sort that list by their ID.
My question here is Is it cheaper performance wise to have 2 lists one holding the transform and the other it's component? Or would it make a difference accessing each component to each transform? (this will be called often.)
I assume having the 2 lists is just a slight increase in memory but a huge savior on performance since it is not required to get the component? I am also assuming getting the component is done with reflection?)
Answer by nsxdavid · Mar 25, 2013 at 04:22 AM
Assuming you have some custom behavior (aka a component script) that represents the creep, then you can have an array of that component. But each component knows what GameObject it is from and what Transform component it has, with the .gameObject and .transform properties.
These are merely substitutes for GetComponent() calls, so it's faster if you store (aka cache) the transform in the transform if you are going access it that way a lot.
lol I'm an idiot... I don't know why I was trying to go one script farther. lol I was getting the ID from a stats script which does not inherit mono. Completely forgetting about my creepController script that uses the creepStats. Thanks for pointing that out.
Your answer
![](https://koobas.hobune.stream/wayback/20220613095030im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Memory Managmenet 1 Answer
(Solved) What is done in preloading ( Application.LoadLevel(x) ) 2 Answers
UI-based game memory and performance issue. 1 Answer
Using baked textures and about texture sizes? 1 Answer
Profiler spikes 1 Answer