Hi All,
learning Unity. Right now to do this I’m creating a dungeon type game. This is seen from above with only the room the players are in is visible. To do this when the players leave a room via a door the next room is triggers. To achieve this when the player collides with the door a script is triggered. This is shown below, this sets the next room active. I do this by using gameobject and find, in the editor I drag the object to the script in the inspector.
So for my demo scene I have room 1 and room 2. Room 1 door has a door script attached to it, I then drag room 2 to be the variable ( gameobject ).
However when I run it I get the following error.
NullReferenceException: Object reference not set to an instance of an object
DoorControl.make_room_to_open_visable () (at Assets/scripts/DoorControl.cs:32)
DungeonMasterScript.OnCollisionEnter (UnityEngine.Collision collisionInfo) (at Assets/DungeonMaster/Scripts/DungeonMasterScript.cs:101)
My collision calls the following door script
publicclassDoorControl:MonoBehaviour
{
publicboolstatus=true;
publicboollocked=false;
publicstringopen_room;
publicGameObjectroom_to_open;
//Usethisfor initialization
voidStart()
{
}
//Updateiscalledonceper frame
voidUpdate()
{
}
public voidmake_room_to_open_visable()
{
room_to_open=GameObject.Find(open_room);
room_to_open.SetActive(true);
}
}
public voidmake_room_to_open_visable is used to set the room.
( sorry text formating from mono losesd spaces when I copy and paste )
Thanks for the advise. 
Should add even if I use the Object name I can’t find it
room_to_open=GameObject.Find("room_2");
Your problem is this
DoorControl.make_room_to_open_visable ()
Somewhere you are making this call. However, DoorControl is your class and since your method isn’t static, you need to create an instance of DoorControl.
public DoorControl doorControl; //Drag and drop or assign your DoorControl through some other way
doorControl.make_room_to_open_visable();
Thank you what I’m doing is this, so the way I’m calling the door is wrong. eg DoorControl door_script=collisionInfo.gameObject.GetComponent();
I’m calling it from a script called dungeonmaster, this script calls it from a collision
if(collisionInfo.collider.tag=="Door")
{
print("It'sadoorreallyneedtoactivateaniationhere");
DoorControl door_script=collisionInfo.gameObject.GetComponent<DoorControl>();
door_script.make_room_to_open_visable();
collisionInfo.gameObject.SetActive(false);
}
I’m a c++ programmer c# scripts appear to be magic right now 
Hi tried that in my dungeon master script eg
publicclassDungeonMasterScript:MonoBehaviour{
publicDungeonMasterMovementDatadungeonmastermovementdata;
publicCameraControlcameraobject;
publicDoorControldoor_script;
......
voidOnCollisionEnter(CollisioncollisionInfo)
{
print(gameObject.name+"and"+collisionInfo.collider.name);
/****************************************************************************/
/*Dooractivation*/
/****************************************************************************/
if(collisionInfo.collider.tag=="Door")
{
print("It'sadoorreallyneedtoactivateaniationhere");
//DoorControldoor_script=collisionInfo.gameObject.GetComponent<DoorControl>();
door_script.make_room_to_open_visable();
collisionInfo.gameObject.SetActive(false);
}
still get on collision error
NullReferenceException: Object reference not set to an instance of an object
DungeonMasterScript.OnCollisionEnter (UnityEngine.Collision collisionInfo) (at Assets/DungeonMaster/Scripts/DungeonMasterScript.cs:101)
:s
This says it’s on line 101, can you tell me what is on that line?
Also, it looks like you commented out the script that assigned a value to your door_script, how are you assigning a value to it if you’re not doing it by that line?
Also, just a note, since you declared a public variable up top, your commented out script should just be
door_script
and not
DoorControl door_script
Hi Sorry,
came in to edit, what I’d done but will print below
One quick question if I do it the way you suggest, what happens if I have 10 doors? Won’t I need a list of 10 objects of I drag the gameobject into script?
The line I commented out is my was my original code I declare the object on line 7 of my code above public DoorControl door_script;
The error line is
door_script.make_room_to_open_visable();
Solved it. Monumental mistake I was trying to find the object by string… Looking at string rather than gameobject. should have been. Embarrassingly stupid when I’ve realised…
publicclassDoorControl:MonoBehaviour
{
publicboolstatus=true;
publicboollocked=false;
publicstringopen_room;
publicGameObjectroom_to_open;
//Usethisfor initialization
voidStart()
{
}
//Updateiscalledonceper frame
voidUpdate()
{
}
publicvoidmake_room_to_open_visable()
{
//room_to_open=GameObje;
room_to_open.SetActive(true);
}
}