- Home /
Referencing all objects in scene
Hey, I've recently been attempting to get a wireframe rendering mode to use with one of my cameras and I've also managed to find a script that turns the object it is attached to render as wireframe. Because I want to render every object as wireframe how would I reference the script on every object and activate/deactivate it?
Many thanks.
A)Is the script already on each object or do you need to add it at runtime? B)And what is the condition to change the state?
I ask those because if it is not on you need to add it obviously. Then the condition because if you use a collision for instance you already have the reference so you would not need to find the object.
The script is already added (but deactivated), and the switching from textured to wiremode will happen when a certain string is entered into a text box and a 'send' button is pressed.
like i said with my answer us that to send whatever activation message to your objects that enables your script to work
there is no all gameObjects button now i didnt make it look pretty because its just the psuedo you can tailor it to whatever needs you have, and litterally spends weeks making it however efficient you want
It actually does not take weeks to make it efficient. It just takes to use GetComponent.
Answer by lil_billy · Nov 19, 2012 at 06:45 PM
var list : GameObject[];
list=gameObject.FindGameObjectsWithTag (tag : String);
for( i in list)
i.sendMessage
following this idea you could do it to just a group of things or could expand it to do all tags thus everything
Answer by fafase · Nov 19, 2012 at 07:03 PM
ok so two solutions, you can go for @lil_billy solution which is fine if you do not do it for many objects at the same time. SendMessage is real slow compare to GetComponent<>();
so the other way:
ComponentName script = GameObject.Find("NameofObject").GetComponent<ComponentName>();
script.TexturedThing = false;
script.Wiremode = true;
NameofObject is the string passed in the textbox I would guess. Since I do not know how you perform the texturing to wiremode I just gave a pseudocoding. I guess you know your script.
yeah i know sendmessage is bad but it was really just a theory example, like i said you could spend weeks cleaning it up to whatever level of efficiency you want, one way would be to replace sendmessage with directly accessing the script on the object. which is sort of what you did, but that to is not good to do with lots of objects
if you want even more efficiency you could use OnBecameVisible to call the function
it really depends on his exclusive situation
this wont work because its only looking for one object you,
The idea is you type in "camera.wiremode" and it'd activate the wiremode component on all the objects. I know how to use GetComponent but I was wondering if rather than having to cache every object I could just search for and activate it on every object.
Well you can cache the component ins$$anonymous$$d of the object. The problem is how will go find the appropriate object? Note that iterating through a limited array will be faster than iterating through the whole hierarchy. If you have a pattern like the ones on the left, then the right on the right,you could group them into array of script references.
Your answer
Follow this Question
Related Questions
Wireframe Rendering on Android 0 Answers
Why color not rendering in my shader? 0 Answers
Getting referencing error when trying to position a GUI screen. 2 Answers