- Home /
Unity3d Flash find object issue
Hi there!
I'm trying to build my project for Flash but I've stumbled upon some problems. Every now and then objects on the scene try to find components of other objects in the scene. Works flawlessly in editor and other builds but I just can't get it to work in Flash.
I have tested with something like this:
private GameManager gm { get { return GameObject.Find("GameManager").GetComponent<GameManager>(); } }
then later on i have:
if (GUILayout.Button(gm.audio.isPlaying.ToString(), mojSkin.GetStyle("ButtonMusicOn")))
{
gm.audio.Stop();
}
the string in the button is just to test what happens and does it even find the object I need.
Results: in editor, on the button it says "true" since the music is actualy playing. When I build and test the flash in browser the button does not render. However, if I remove the string in the button completely, then it renders the button in flash without issues. There are some other similar situations where the code just stops because it's trying to access a component of a different object which led me to a conclusion that GameObject.Find does not work.
Any help is appreciated due to contest deadline. Thank you.
I have also tried referencing the object from within the Start() function but with no success.
Strangely enough, making a new project and trying to reference an object - it works! now im completely confused.
It appears that any object and/or class should not be named Game$$anonymous$$anager. I have tried several times. I've created an empty project, started from scratch looking for a way to make reference to another object. Having no game on $$anonymous$$d I just named my objects and classes SomeGUI and SomeClass. I tried to reference the object and it worked (my 2nd comment).
I then started a new project with a game on my $$anonymous$$d and started na$$anonymous$$g objects logically, like Game$$anonymous$$anager. As soon as I tried the build, the reference was not done. After some contemplating, I decided to rename my objects and classes to something like Game$$anonymous$$kk and it worked.
Went back to my old project and renamed EVERYTHING named Game$$anonymous$$anager to Game$$anonymous$$ontroler (notice the $$anonymous$$ and a single L in $$anonymous$$ontroler - this was intentional) inside it and voila, the build is perfect.
Answer by vlePa · Dec 28, 2011 at 09:45 PM
Do not name your objects and/or classes "GameManager" as it appears to be a keyword.