Type or namespace State could not be found

Hello guys, I need some help. I’m stuck at Section 3 Lecture 24 @06:20

I’ve followed the video and I’ve done everything as the video says, but State doesn’t exist. Auto-completion doesn’t occur in State.cs either. Do anyone know what I’ve done wrong or need to do?

Unity version: “2018.2.17f1 Personal”
Visual studio: “2017 Community”

“Type or namespace State could not be found (are you missing a using directive or an assembly reference?”

Suggestions from VS:
" using UnityEditorInternal "
" using static UnityEngine.Random "
" Fully qualify ‘State’ "
" Generate type ‘State’ "
" Fix typo ‘State’ "

Screenshot of unity:
https://drive.google.com/file/d/17YclDqYdWY9WgfWgCKZQbCJXaBKXu-95/view?usp=sharing

My scripts:

Adventure.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class AdventureGame : MonoBehaviour {

    [SerializeField] Text textComponent;
    
    // Errors occur here
    [SerializeField] State startingState;
    State state;

	// Use this for initialization
	void Start () {

        // and here
        state = startingState;

        textComponent.text = "This is added programatically";
    }
	
	// Update is called once per frame
	void Update () {
		
	}
}

State.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(menuName = "State")]
public class State : ScriptableObject {

    [TextArea(14,10)] [SerializeField] string storyText;

    public string GetStateStory()
    {
        return storyText;
    }
}

Hi,

There is currently an issue with the Visual Studio Tools for Unity which may be causing this issue for you.

Lets see if we can work it out.

First of all, in Visual Studio, if you look under Solution Explorer is the project open, or does it state “0 Projects”?

If the project is open, is the State.cs class listed in Solution Explorer?

Incidentally, you can just upload your images directly to your forum post, makes them a bit easier to see.


See also;

Hi Rob.

Thank you for your fast answer.

There is 1 project open, but I only see AdventureGame.cs under Solution ‘Text 101’ (1 project) -> Assembly-CSharp -> Assets.

Will I have to manually add State.cs to the solution?

Thank you for saying that, I didn’t notice that there was an upload button :smile:

Hi,

This sounds like the issue with Visual Studio Tools for Unity.

What’s happening is when you create your script in Unity, Visual Studio isn’t reloading the project and thus it doesn’t show the new scripts, State.cs in this case.

To confirm this is the case, close Visual Studio and then double-click State.cs from within Unity to re-launch Visual Studio, you should now see the file listed and all of the intelli-sense that wasn’t available within State.cs previously should now work.

If you can confirm this I can then point you to a potential short-term fix until a new release of Visual Studio Tools for Unity / Visual Studio is rolled out.

Case confirmed.

The intelli-sense is back, State.cs is in the project and State exists in AdventureGame.cs. :slight_smile:

1 Like

Great, that means we can do something about it easily.

I posted about this issue here a few days ago;

Have a read through, it’ll describe the behaviour you are experiencing and in the follow-up I posted to it you’ll see a link to a topic on the Visual Studio Support site, where Sebastien has stated that he will provide a preview version which resolves this issue. I did ask if I could publicly share this file but I was asked not to, hence the link back to him to get it. I did put his contact details in my reply also.

The result will be you getting an email from Sebastien with a link to a .vsix file, make sure Visual Studio is closed, then run it, it will install Visual Studio Tools for Unity into Visual Studio, you’ll note that the version number changes from 3.9.0.2 (I’m guessing this is what you have?) to 3.9.0.3.

After installing this your project will automatically reloading within Visual Studio again when you add/remove scripts from Unity.

One minor thing I’ve noticed so far is that on occasion I get duplicate scripts opened in Visual Studio, same file name but with “2” appended to them, if you see this too, just right-click on a file and choose “Close All” for example, that gets them out of the way allowing you to re-open the file you want to work on. This is a separate Visual Studio bug which has also been identified and I believe both of these will be resolved in the next rollout, but I don’t know when that will be.

The above solution is much more convenient than constantly closing Visual Studio and re-opening it each time you add a new script to Unity but that is also an option if you prefer.

Hope this helps :slight_smile:

1 Like

I’ll give it a read and try the solution.

Thank you alot for your time, now i can finally get further into the project. :slight_smile:

1 Like

You’re very welcome.

My own productivity took a bit of a battering last week when I encountered this, I spent far too much of my time trying to work out why the project wasn’t reloading. Got there eventually and so far the updated version has been a life-saver. Definitely worth spending the time to ping Sebastien an email in my opinion. He replied within 24 hours when I contacted him.

Good luck and I’m glad you can move forward again :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms