Console blank when running script ( 0 does not change to 1)

1 Like

Hi @3DRaddict, just to check, but have you added this script to an object within the Main scene yet?

I thought I had, but obviously I hadn’t ! …thanks Rob

1 Like

You’re welcome Allan :slight_smile:

Hi Rob,

Sorry, same issue happened to me. How do i add the script to an object main scene?

thanks.

1 Like

Hi @MZY, with your scene selected, select the object in the hierarchy view and then simply drag and drop your script onto the selected object within the Inspector. Alternatively, you could select Add Component within the Inspector whilst the object is selected, then select Script and select your chosen script file.

Hope this helps.

2 Likes

I’m having the same problem but your solution isn’t working for me. The script is grayed out when I try to add it from the “Add Component” menu item and it won’t let me drag and drop the script.

Hi @ntolman, can you pop a screenshot up for me please :slight_smile:

Here it is.

So, if you select your scene under Assets called NumberWizard, what do you see then? (another screenshot please)

Hi,

No, I mean here…

The “NumberWizard” in the red circle with the Unity icon to the left is your “scene”, at the moment you are not selecting a scene. If you select the scene, what can you see then? I would expect some items (at least a camera) to appear in the hierarchy (top left pane as you have it now).

Can you click on the NumberWizard scene and then take a screenshot please (it helps me try to talk you through etc)

Like this?

Perfect…

Ok, so, you have selected the NumberWizard scene from within the Project View. In the Hierarchy view you can now see a Camera.

At the moment, which you have a NumberWizard script (the file below the scene), it isn’t attached to anything. We could do with seeing some properties of the Camera. So, if you now click on the Camera under the Hierarchy view, normally you would see the properties of this object appear in what’s called the Inspector. It typically appears on the right hand side, yours pane for this may not currently be visable. First, try selecting it and see if the Inspector pane appears, if not, we will need to display it. Right click on the Console tab and select Add Tab, then choose Inspector.

When you can see the properties of the Camera you should also see a button underneath them which says “Add Component”. You can click on that, and then select your NumberWizard script file, or, simply drag the script file onto the inspector and it will automatically add the script component.

Once the script is actually attached to something, the code inside it can run. At the moment it is just sitting there, not being called. So, with the script attached to the camera (for now), run the game. All being well you should see the message you typed in your script appear in the Console pane (top right as you have it at the moment).

Some images to help…

(note I renamed my camera to “Main Camera” - doesn’t make any difference at this stage)

(inspector tab is displayed, and it shows all of the properties of the camera, including the Add Component button)

(adding the component)

(select Scripts and your NumberWizard script will be displayed)

Let me know how you get on…

Update

If it helps, it’s covered in better detail in lecture 15, section 2. The one difference I have spotted between what I have put and the course is that Ben deletes the camera and creates an empty game object which he then calls NumberWizard, the script is then attached to that. It shouldn’t make much difference if you follow the above, the main issue you are having I believe is that your script just isn’t attached to anything, thus the code doesn’t run :slight_smile:

Thanks! It works now. I knew I was doing something wrong, I just wasn’t sure what.

1 Like

Great news Nick, well done :slight_smile:

Probably best to get the project back in line with the course though, e.g. delete the camera and then add a new empty game object in the hierarcy, rename it to NumberWizard and then re-add your script to that instead. Should make it easier to continue with the rest of this section :slight_smile:

It should be noted here, and hopefully corrected in the course (assuming I didn’t miss something) that when Ben originally tells you to run the game with the “Welcome to Number Wizard” print command in the NumberWizard script, he hasn’t told you to make these connections in Hierarchy.

This solution solved the problem for me. Again, maybe I missed him explaining it (trying to study with 6 year olds running around), but I’m about 95% sure I didn’t.

For reference, I am on Section 2: Lecture 15 at the 6 minute mark or so.

The solution for those hitting the same wall as me is listed above, but to simplify:

On the Heirarchy tab on the left near the top (in default view), click NumberWizard. On the right under the Inspector tab click Add Component > Scripts > Number Wizard. (this is all assuming you followed his directions precisely)

Running the game should now display your print command results in the console.

EDIT:

I’m going to make a new thread about this to clarify if I am making a mistake or if I missed something in the lecture. Look for that post in the main section for this lecture.

EDIT:

To clarify, at this point, he hasn’t told you that you SHOULD use Add Component to add the script to Assets. He explains that you can add the script by right clicking in Assets or by clicking Add Component in the Inspector. If you watch his movements, he adds the script via Inspector > Add Component. If you do this, you will have no problems. However, if you add the script by right clicking inside the Assets tab, you have use Add Components in the Inspector and add the script you have already created. I have experienced problems doing it this way (the script seems to disappear from the Inspector occasionally, and I have to Add Components again to reconnect the script), so I recommend starting with the Add Component button to create a new script.

1 Like

Thanks for the help guys. I had the same issue after it gave me a compiler error message. I corrected my scripts but kept getting error messages. Rebooted Unity and couldn’t get it to play in the console. This thread helped me realize I was forgetting the game object. Created new empty game object, added my NumberWizard scripts to it and now works fine.

1 Like

I was facing the same issue, but now it is running. Thanks @Rob. :slight_smile:

1 Like

You’re more than welcome, glad you have it working @Emilson_Vontade :slight_smile:

Privacy & Terms