Search Unity

Since upgraded to Unity 5, can't get any custom variables in C# (MonoDevelop)

Discussion in 'Scripting' started by Max_Bol, Mar 29, 2015.

  1. Max_Bol

    Max_Bol

    Joined:
    May 12, 2014
    Posts:
    168
    Hello all.

    I got this strange problem with MonoDevelop and Unity 5.
    I can't seem to create any custom variables in C#.

    As an example of uses that previously worked, but not anymore:

    In script "FirstScript" (in C#) on the GameObject "Source", I got a public bool called "b1" which is true or false;

    In another script called "SecondScript" on the GameObject "Receiver", which contain the following script :

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System;
    4. using System.Collections;
    5.  
    6. public class SecondScript : MonoBehaviour{
    7. private FirstScript firstScript;
    8.  
    9. void Start(){
    10. firstScript =GameObject.Find("Source").GetComponent<FirstScript>();
    11. }
    12. void Update(){
    13. if(!firstScript.b1) return;
    14.  
    15. **blablabla**
    16. }
    I know this isn't much of use at it is, but what I want to ask is why is "private FirstScript firstScript;" not working at all? For some reasons, it always notice me that I'm missing a directive or assembly reference and "FirstScript" is red as not found;

    The only way I can "get" the "FirstScript" recognized is by using "private component firstScript", but then I can't access b1 value as "firstScript.b1" is not working anymore. (Well, not that I can say it worked previously since I couldn't call the "firstScript" as a "FirstScript" variable, but you get the point)

    Never had this kind of problem when I was using MonoDevelop with Unity 4.X and what's strange is that all my previous scripts are working... but not anything I make in MonoDevelop with Unity 5.0.

    Am I the only one with this issue or can anyone assist me in understanding what's wrong there?
     
  2. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    That sounds strange. Are you sure you are creating the script in the right assembly (aka editor or runtime assembly, referring an editor script from a runtime script wont work). Maybe it is in another namespace?

    If you are on windows, I would seriously recommend to switch over to Visual Studio Community anyway together with the UnityVS plugin as MonoDevelop is a true piece of sh*t compared to VS
     
  3. Max_Bol

    Max_Bol

    Joined:
    May 12, 2014
    Posts:
    168
    The problem is coming from the Engine (it seems). MonoDevelop only mark the error, but is not the cause of it. The error appear even if I'm using notepad. The strange thing is that I can copy/paste the lines from previous works of mine and they seem to works... but typing the exact same line manually bring out the error. o_O

    I'll try to re-install Unity 5 as it might be a broken local assembly process.
    Now (which I didn't had prior), whenever I open any scripts upon opening a project, I get an error pop-up message about the project' SLN file and there's a tab, in MonoDevelop that automatically open with the following content (content of the SLN file) :

    Code (CSharp):
    1. Microsoft Visual Studio Solution File, Format Version 11.00
    2. # Visual Studio 2008
    3.  
    4. Project("{665A6755-A760-6B08-7D28-AD39357942A7}") = "*Project Name*", "Assembly-CSharp-firstpass.csproj", "{1F7230A8-72F9-06F3-278E-D472287FEA50}"
    5. EndProject
    6. Project("{665A6755-A760-6B08-7D28-AD39357942A7}") = "*Project Name*", "Assembly-CSharp.csproj", "{7B1871DB-BBE7-0CB3-8825-C25E617BA1A7}"
    7. EndProject
    8. Project("{665A6755-A760-6B08-7D28-AD39357942A7}") = "*Project Name*", "Assembly-CSharp-Editor.csproj", "{290F5EC3-5B2B-EB37-3724-1C2E6D257C14}"
    9. EndProject
    10. Global
    11.     GlobalSection(SolutionConfigurationPlatforms) = preSolution
    12.         Debug|Any CPU = Debug|Any CPU
    13.         Release|Any CPU = Release|Any CPU
    14.     EndGlobalSection
    15.     GlobalSection(ProjectConfigurationPlatforms) = postSolution
    16.         {1F7230A8-72F9-06F3-278E-D472287FEA50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    17.         {1F7230A8-72F9-06F3-278E-D472287FEA50}.Debug|Any CPU.Build.0 = Debug|Any CPU
    18.         {1F7230A8-72F9-06F3-278E-D472287FEA50}.Release|Any CPU.ActiveCfg = Release|Any CPU
    19.         {1F7230A8-72F9-06F3-278E-D472287FEA50}.Release|Any CPU.Build.0 = Release|Any CPU
    20.         {7B1871DB-BBE7-0CB3-8825-C25E617BA1A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    21.         {7B1871DB-BBE7-0CB3-8825-C25E617BA1A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
    22.         {7B1871DB-BBE7-0CB3-8825-C25E617BA1A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
    23.         {7B1871DB-BBE7-0CB3-8825-C25E617BA1A7}.Release|Any CPU.Build.0 = Release|Any CPU
    24.         {290F5EC3-5B2B-EB37-3724-1C2E6D257C14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    25.         {290F5EC3-5B2B-EB37-3724-1C2E6D257C14}.Debug|Any CPU.Build.0 = Debug|Any CPU
    26.         {290F5EC3-5B2B-EB37-3724-1C2E6D257C14}.Release|Any CPU.ActiveCfg = Release|Any CPU
    27.         {290F5EC3-5B2B-EB37-3724-1C2E6D257C14}.Release|Any CPU.Build.0 = Release|Any CPU
    28.     EndGlobalSection
    29.     GlobalSection(SolutionProperties) = preSolution
    30.         HideSolutionNode = FALSE
    31.     EndGlobalSection
    32.                                                     GlobalSection(MonoDevelopProperties) = preSolution
    33.         StartupItem = Assembly-CSharp.csproj
    34.         Policies = $0
    35.         $0.TextStylePolicy = $1
    36.         $1.inheritsSet = null
    37.         $1.scope = text/x-csharp
    38.         $0.CSharpFormattingPolicy = $2
    39.         $2.inheritsSet = Mono
    40.         $2.inheritsScope = text/x-csharp
    41.         $2.scope = text/x-csharp
    42.         $0.TextStylePolicy = $3
    43.         $3.FileWidth = 120
    44.         $3.TabWidth = 4
    45.         $3.IndentWidth = 4
    46.         $3.EolMarker = Unix
    47.         $3.inheritsSet = Mono
    48.         $3.inheritsScope = text/plain
    49.         $3.scope = text/plain
    50.     EndGlobalSection
    51.  
    52. EndGlobal
    53.  
    In the above code, I only have changed the project's actual name (which is a Work in Progress) for *Project Name*.
     
  4. Max_Bol

    Max_Bol

    Joined:
    May 12, 2014
    Posts:
    168
    I wish to share more information (for those who might come across this kind of issue).

    The problem seems to come from a broken or incomplete library located inside of the Standard Example Project assets packages. (Remember that those packages were made with the Beta version of Unity 5 so the bug might be fixed in the current Unity 5.0 if you're building the scripts and asset yourself)

    Reinstalling Unity 5 (after a full uninstall + clean up) didn't helped at all with previously made project.
    Importing a package made within the previous project didn't helped at all neither.

    I have tried to create a pure clean (and new) project file and the problem doesn't seems to be there or, at least, the most I got was the following pop-up error :

    Code (CSharp):
    1. System.NullReferenceException: Object reference not set to an instance of
    2. an object.
    3.   at
    4. Mono.Addins.ExtensionNode.add_ExtensionNodeChanged(ExtensionNodeEventHandler
    5. value) in
    6. c:\buildslave\monodevelop\build\monodevelop\main\external\mono-addins\Mono.Addins\Mono.Addins\ExtensionNode.cs:line
    7. 169
    8.   at Mono.Addins.ExtensionContext.AddExtensionNodeHandler(String path,
    9. ExtensionNodeEventHandler handler) in
    10. c:\buildslave\monodevelop\build\monodevelop\main\external\mono-addins\Mono.Addins\Mono.Addins\ExtensionContext.cs:line
    11. 693
    12.   at Mono.Addins.AddinManager.AddExtensionNodeHandler(String path,
    13. ExtensionNodeEventHandler handler) in
    14. c:\buildslave\monodevelop\build\monodevelop\main\external\mono-addins\Mono.Addins\Mono.Addins\AddinManager.cs:line
    15. 726
    16.   at MonoDevelop.Projects.ProjectService..ctor() in
    17. c:\buildslave\monodevelop\build\monodevelop\main\src\core\MonoDevelop.Core\MonoDevelop.Projects\ProjectService.cs:line
    18. 90
    19.   at MonoDevelop.Projects.Services.get_ProjectService() in
    20. c:\buildslave\monodevelop\build\monodevelop\main\src\core\MonoDevelop.Core\MonoDevelop.Projects\ProjectsServices.cs:line
    21. 40
    22.   at MonoDevelop.Ide.Services.get_ProjectService() in
    23. c:\buildslave\monodevelop\build\monodevelop\main\src\core\MonoDevelop.Ide\MonoDevelop.Ide\Services.cs:line
    24. 41
    25.   at
    26. MonoDevelop.Ide.RootWorkspace.BackgroundLoadWorkspace(IProgressMonitor
    27. monitor, String filename, Boolean loadPreferences, Boolean reloading) in
    28. c:\buildslave\monodevelop\build\monodevelop\main\src\core\MonoDevelop.Ide\MonoDevelop.Ide\RootWorkspace.cs:line
    29. 578
    But once the pop-up error window closed, everything was working as it should.
    Then, I tried to import just some of the scripts and prefabs from the Standard Example Project assets packages (the 3rd Person Character (and all its related scripts) + the FreeLookCamera prefab in which I added some variables to its main script + the Effect package)
    I could still do the exchange of the variables' values between any scripts I manually made, but couldn't do it (the exact same scripts and variables) in any of the Example Project related scripts (even those which I had previously modified).

    In other words, I have to keep clear of the any scripts used in the Standard Example Project and build my own version of it from scratch. Well, that was not part of my plan for the upcoming weeks, but guess I have to do it. :confused: