Namespace not being assigned [Fixed!]

Haya im experiencing an issue where my namespace is no longer being defined upon using this code:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEditor;
using Analyzer;
using System.Threading;
using UnityEngine.Networking;

public class LBDS : MonoBehaviour{
    public Main main = new Analyzer.Main();
    // Other code below
}

and my namespace is just this:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEditor;
using Analyzer;
using UnityEngine.Networking;

namespace Analyzer{
    public class Main : MonoBehaviour {
        // All other code here
    }
}

Furthermore unity seems to be referencing the namespace as a script like this (Don’t worry about the names i took this image after a few changes but i’ve reverted them):6753208--779026--A.png
(if an image doesn’t show up here its because i don’t have permissions because im a low tier user so to put it simpler ~ in the unity editor the main variable is shown as an assignable script which it shouldn’t be doing since it’s a namespace)

However other namespaces seem to work and the only error i get is when running the code and that just saying how the main variable is unnassigned

I’ve tried rebuilding my csproj files aswell but that did nothing - aswell as changing to multiple versions
Any help will be greatly appreciated, tnx

Smells like maybe a recompile didn’t get triggered. Try reimporting one of the scripts.

Just tried reimporting an refreshing both scripts; doesn’t work unfortunately

Update: Just completely deleted both scripts then remade them and copy and pasted the code - something seriously wacky is going on from what i can workout - and if it is my code i have no idea why it continues to be referenced as a script since ive even tried changing the namespace

Am I reading this wrong, or are you trying to create an instance of the Main MonoBehaviour using “new” in the first line of the LBDS script? Unity doesn’t like that.

1 Like

Aha! ye just figured it out after reading Joe-Censored’s comment i didn’t realise i was using a monbehaviour in my namespace like a muppet :sweat_smile: and of course that doesn’t work

Ty for the help you 2 :slight_smile:

1 Like

You can do this all day long, you just have to use .AddComponent<Analyzer.Main>() instead.

huh i didn’t know this was possible, cheers again :slight_smile: