Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Namespace not being assigned [Fixed!]

Discussion in 'Editor & General Support' started by bobby55, Jan 22, 2021.

  1. bobby55

    bobby55

    Joined:
    Jun 24, 2020
    Posts:
    48
    Haya im experiencing an issue where my namespace is no longer being defined upon using this code:

    Code (CSharp):
    1.  
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using System.Linq;
    6. using System.Text;
    7. using UnityEngine;
    8. using UnityEditor;
    9. using Analyzer;
    10. using System.Threading;
    11. using UnityEngine.Networking;
    12.  
    13. public class LBDS : MonoBehaviour{
    14.     public Main main = new Analyzer.Main();
    15.     // Other code below
    16. }
    17.  
    and my namespace is just this:

    Code (CSharp):
    1.  
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using System.Linq;
    6. using System.Text;
    7. using UnityEngine;
    8. using UnityEditor;
    9. using Analyzer;
    10. using UnityEngine.Networking;
    11.  
    12. namespace Analyzer{
    13.     public class Main : MonoBehaviour {
    14.         // All other code here
    15.     }
    16. }
    17.  
    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): 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
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    Smells like maybe a recompile didn't get triggered. Try reimporting one of the scripts.
     
  3. bobby55

    bobby55

    Joined:
    Jun 24, 2020
    Posts:
    48
    Just tried reimporting an refreshing both scripts; doesn't work unfortunately
     
  4. bobby55

    bobby55

    Joined:
    Jun 24, 2020
    Posts:
    48
    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
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    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.
     
    Kurt-Dekker likes this.
  6. bobby55

    bobby55

    Joined:
    Jun 24, 2020
    Posts:
    48
    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 :oops: and of course that doesn't work

    Ty for the help you 2 :)
     
    Joe-Censored likes this.
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    You can do this all day long, you just have to use
    .AddComponent<Analyzer.Main>()
    instead.
     
  8. bobby55

    bobby55

    Joined:
    Jun 24, 2020
    Posts:
    48
    huh i didn't know this was possible, cheers again :)