- Home /
A question of optimization: use a script with variables or use the object name?
Hi. I have script where you can build a level just by moving walls (like in Portal 2) I'm currently working on highlighting walls so that you can move them (already got the "building part" of the script done - long story).
It basically works like this:
You have an built-in Array (with six wall slots) in an Array (z-axis) in an Array (y-axis) in an Array (x-axis).
You changing the max size of the level that you want by changing the size of the arrays.
So when you want to get a reference to the 4th wall "grid position" of x=5,y=7,z=3, you just type
x[5].y[7].z[3].w[4].o
("o" as for object, its a class with o as object, h as if highlighted)
It works for now. But as I mentioned, I need to find a way to highlight the walls when you click them.
Now the names of the walls look like (for the example above) "5734". I thought about reading those numbers to get a reference in the arrays, but it's only easy if the numbers are <10. If they were larger, I would have to find a way to change "5" to "005" and "50" to "050", set it to the name of the wall, and read it when you click on it to highlight it.
When you think about that, it's quite hard to achieve and doesn't affect the performance positively.
So I'm asking: is it better to use the name thing with parsing etc. or to just put a simple script with variables only on each of the walls with their XYZW?
Thanks.
Answer by Ejlersen · Aug 06, 2013 at 07:25 PM
I would go with a script that has its indices.
Reason:
You don't need to parse a string to get its indices, so its faster.
Hmm... Ive thought about that, but Ive got sometimes even thousands of walls, so a thousand of scripts... Doesn't that affect the performance?
True, but if you have thousands of walls, which is thousands of game objects with thousands of colliders. Then a small script like that is the least of your problems.
Your answer
Follow this Question
Related Questions
C# basic perfomance question 2 Answers
How to access scripts other than by name. 1 Answer
Optimized Scripting - Variables 1 Answer
Static variables optimization 2 Answers
Which is more optimal? Defining variables or calling Resources.Load? 2 Answers