0
\$\begingroup\$

I moved my Visual Scripting from an embedded graph into a State Machine graph as a file.

Suddenly started getting this error...

MissingComponentException: there is no Camera attached to the gameobject but a script is trying to access it.

The offending node is a Camera Screen to World Point.

There wasn't a Camera component attached to this gameobject previously and it worked (thr gameobject is under the Main Camera).

Any advice on what went wrong, and how to fix it?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ In case you get script errors, we would need to see the script and how it is attached to your gameobject \$\endgroup\$
    – Zibelas
    Commented May 23, 2022 at 5:39

3 Answers 3

1
\$\begingroup\$

I suspect that it is the Camera which got untagged: for automatic code (Camera camera = camera.main; OR here visual scripting), it needs to be tagged.

In the editor, select the camera, scroll down the drop-down menu in front of tag, and select "Main Camera". enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ Just checked and unfortunately, it's already tagged as MainCamera... was so hoping this was the issue!! Thanks for posting! \$\endgroup\$
    – kanamekun
    Commented May 23, 2022 at 21:53
1
\$\begingroup\$

I had moved my Visual Scripting code from Embedded (in the GameObject) to Graph. By making it a separate Graph file, I had hoped that multiple GameObjects could use the same code.

But when I moved the code, the Camera input for my "Screen to World Point" node changed. It used to be set to "Main Camera", but now that option had disappeared and it was set to "This".

I went to change it back to Main Camera, but there was no option to do so. In fact, when I clicked to "Select Camera "... the entire Scene tab had disappeared, and along with it the Main Camera option.

I moved the same Visual Scripting code to being Embedded and the Main Camera option reappeared. All code working again!

Not sure how to move this code to a Graph and have the Camera still work, but that is a separate issue. Thank you to all who answered and commented and helped steer me to the answer!!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ It sounds like you're running into a similar issue as users trying to reference scene objects from prefabs. If you make a reusable graph, then it can potentially be reused in other scenes. So it can't reference objects in one particular scene that may not be loaded when the graph is used. You may instead need to search for the appropriate camera, or cache a reference to it somewhere that's easy to find, or assign it on a per-instance basis. \$\endgroup\$
    – DMGregory
    Commented May 23, 2022 at 22:54
0
\$\begingroup\$

Reason: Your script is trying to get the camera component from a Game object but is unable to find it.

Solution: Inspect that the correct game object is assigned from which you want to access the camera component. If the component is correct then, check whether the camera component is attached or not.?

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .