- Home /
Can't assign camera by dragging it into GUI
Hi everyone. I've created two public Cameras, like this;
public Camera defaultView;
public Camera playerAction;
However, when I try to drag a camera from my Hierarchy view to the inspector, it does nothing, I don't get a prompt, and it remains unchanged, like this
The camera I'm intending to drag is called _Camera, if it means anything. I'm currently using Unity 4
Works fine for me and should for you. Do you see your cameras if you click the little circle 'o' thingy?
I see them, and attempting to add them through that menu yields the same results. Are you using unity 4? I switched recently and I have the feeling that it may be the cause
Yea, I'm in 4. You may be right about a merge being the cause. I couldn't say. Sucks, but yea... Should work :|
Answer by Captain_Dando · Mar 18, 2013 at 11:06 AM
After a lot of testing I discovered that I had a script named Camera that was conflicting with Unity's own Camera behaviour. changing the name seems to have solved it. This didn't show up in the console until I removed all of the scripts and added them back in
Answer by Bunny83 · Mar 11, 2013 at 01:26 PM
I guess you try to assign a scene object to a variable in a prefab which doesn't work. Prefabs can only reference objects from the project but not form a scene since it's not geven that the scene is loaded when you use the prefab.
The object I'm referencing, and the objects I'm referencing are not prefabs, they are arranged as you see below, the script is kept on the _Game $$anonymous$$aster game object.
hough from what you describe I think this may be caused by the camera loading after the script has run. Is that kind of thing possible?
No, not really. Hopefully you talk about assigning the references at edit-time?! If the script containing the variables is also a scene object there should be no problem assigning other scene objects. Do you use a custom inspector for your class?
Usually it doesn't matter, but do you drag the gameobject onto the variable or the component? To drag the component you have to open another inspector window (the "tab"-context-menu at the top right of an editorwindow) and select "Add Tab" -> "Inspector". Lock one of the inspector windows on your manager object by clicking the lock icon at the top of the inspector. Now you can select your other object that has the camera component attached. Now grab the components header line and drag it over to the variables.
Btw: Does the cursor change when you enter the variable field while dragging the component / gameobject? Are you sure you don't have any strange editor scripts somewhere (AssetPostProcessors, ....)?
Does the script have the ExecuteInEdit$$anonymous$$ode attribute? If so is there any code in Update which could overwrite the content of your variables?
I've moved my projects to U4 quite a while ago. I had some issues, but mainly "SetActive" stuff. All in all i migrated without any unexpected trouble.
I definitely add it during edit time, and I've not ventured into custom inspectors so I don't think that might have been the problem. I drag the camera from the hierarchy to the camera field on my script (component) on my Game $$anonymous$$aster Gameobject. When I am dragging it over the field it is surrounded by a blue outline, as it should be, but when I let go, nothing happens.
The camera itself is a generic camera added though unity's menus, withou any special components. both are unable to be added, so I think it's a problem with the Game $$anonymous$$aster script. I'm not aware of any AssetPostProcessors, and I don't have anyhing like tha in my script. it also doesn't have an Update function currently.
On a side note, on a previous project I created a camera variable in the same way, while watching a tutorial. I followed his script to a tee, but when I was told to drag the camera onto the component, nothing happened, so I think something may be wrong with unity, or I changed something and can't remember what it was. Other data types, such as textures can still be applied in that way though.
Your answer
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
Problem exposing public variable to Inspector in C# 2 Answers
script is treating all enemies as one, instead of them as individuals. 2 Answers
public private and static variables in js 1 Answer
Variable Not Changing In Method 1 Answer