- Home /
Class definition not recognized after load level
General description: I just migrated my awesome game from unity 3.5 to 4.5. All objects seem to be ok. The game runs, but now it has some extrange behaviour.
Detalis: I have defined a couple of classes inside the Plugin folder, for instance this one:
using UnityEngine;
using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
public class MapsClass : MonoBehaviour {
//Variables or attributes - Start
public String MapName;
public String MapLoadName;
public Texture MapLoadTexture;
public int MapMaxRunners;
public int GoldCost;
public int BronzeCost;
public int ReqLevel;
public int FirstPlacePrize;
public int SecondPlacePrize;
public int ThirdPlacePrize;
//Variables or attributes - End
public MapsClass (String mapName,String mapLoadName,Texture mapLoadTexture, int mapMaxRunners, int goldCost, int bronzeCost, int reqLevel, int firstPlacePrize, int secondPlacePrize, int thirdPlacePrize){
//MapsClass theMap = new MapsClass();
MapName = mapName;
MapLoadName = mapLoadName;
MapLoadTexture = mapLoadTexture;
MapMaxRunners = mapMaxRunners;
GoldCost = goldCost;
BronzeCost = bronzeCost;
ReqLevel = reqLevel;
FirstPlacePrize = firstPlacePrize;
SecondPlacePrize = secondPlacePrize;
ThirdPlacePrize = thirdPlacePrize;
//return theMap;
}
public MapsClass(){
MapName = "";
MapLoadName = "";
MapLoadTexture = null;
MapMaxRunners = 0;
GoldCost = 0;
BronzeCost = 0;
ReqLevel = 0;
FirstPlacePrize = 0;
SecondPlacePrize = 0;
ThirdPlacePrize = 0;
}
}
Now, the class is referenced inside a normal JS which holds this instruction: DontDestroyOnLoad(transform.gameObject);
The same script has a variable defined as: var CurrentMap : MapsClass = null;
On running the game, the variable gets its default value. Then, when I hit the "Lets run" button, the expected level is loaded (another proof that the value was stored), but inside the level, another scripts calls the variable and I get the following error on this line:
Debug.Log('Player Name: ' + mpManager.PlayerName);
if (mpManager.CurrentMap.MapName == 'Londinum' && mpManager.enable_Lap)
{
newPlayer.transform.Rotate(Vector3(0,180,0));
}
Error: NullReferenceException: Object reference not set to an instance of an object
The Debug line retrieves a correct value from my "Do not destroy on load" super script which is here refered as to "mpManager". The value not recognized is this one: mpManager.CurrentMap.MapName.
Question: Since this thing was running ok in unity3, WTF do I need to do in order to make it run in unity4?
If you help me get the solution a paypal deposit of $20 will be delivered to your account. Thnx in advz for any answer.
Since the issue is raised for mp$$anonymous$$anager then you should post the code of that script too. Anyway it seems that mp$$anonymous$$anager or Current$$anonymous$$ap is not set at the time you call the function where the exception is raised.
Your answer
![](https://koobas.hobune.stream/wayback/20220613174818im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Class error: BCE0019: 'xxxx' is not a member of 'Object'. 0 Answers
The name '' does not exist in the current context 2 Answers
Access to a variable inside a C# class 2 Answers
Can a class hear a broadcast message? 0 Answers
How can I use method to return custom classes (Same Class Type),How to return classes in method 1 Answer