Unity3D: MissingReferenceError when destroying a GameObject from OnInspectorGUI

If you’re like me you use lots of custom inspectors and windows in your Unity project. Keeping things organized and easier to use. However, every once in a while you come across some weird ‘bug’ that makes you want to do things that are not for the betterment of humankind.

Today’s issue is getting a missing reference error that looks something like this.

  • MissingReferenceException: The object of type ‘ValveAnim’ has been destroyed but you are still trying to access it.
  • Your script should either check if it is null or you should not destroy the object.
  • UnityEditor.Editor.IsEnabled () (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:589)
  • UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/ buildslave/unity/build/ Editor/Mono/Inspector/InspectorWindow.cs:1151)
  • UnityEditor.InspectorWindow.DrawEditors (UnityEditor.Editor[] editors) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1028)
  • UnityEditor.InspectorWindow.OnGUI () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:352)
  • System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/ buildslave/mono/build/mcs/class/corlib/ System.Reflection/MonoMethod.cs:222)

This error occured when I tried to replace a gameobject (prefab instance) through a custom inspector from one of its components. This inspector would show the prefabs that are compatible with the input data, which you can then select and replace the existing gameobject.

This is done simply by creating an instance of the selected prefab, copying over some small amount of data from the original, and then destroying the original. Seems simple right?

prefab-error

Yet errors occur. This might make you wonder, where exactly did you do something wrong? You’d check to see if any of your inspectors or windows are trying to access that missing component and as you check things it seems that you’re doing everything okay. It turns out it is Unity’s own inspectors/windows that are trying to render the inspector but fail to find the components and then they proceed to tell you “Your script should either check if it is null or you should not destroy the object.” Blaming you, but as the error shows it’s coming from inside Unity itself.

In our case the gameobject we destroy has more components than our SensorPrefab, the next in line is the ValveAnim, which is mentioned in our error message. So, you’d say, why doesn’t Unity just stop drawing the inspector tab if the selected gameobject gets destroyed? I have no idea but we have a handy little function that tells it to do just that.

GUIUtility.ExitGUI();

This will tell it to stop what the hell it’s doing and just go with the flow, man! Now you can destroy your own gameobjects from their own inspectors without those pesky little error messages.

Thanks to margutteter for stopping me from killing myself. (http://answers.unity3d.com/answers/953420/view.html)

Thoughts on: I am alive’s ending

It has been about six months since my graduation to ‘bachelor of multimedia-design’. My school career ending as it were with a thesis on horror game-design which I aim to ‘publish’ in the near future. Having researched many horror games it seems strange that ‘I am alive’ stayed under the radar for me. Only having heard of it recently I decided to try out this game that in so many respects piqued my interest.

Word on the street was that the game had some nice ideas but its long development cycle with many setbacks were its downfall; great concept but poor execution. This made me hesitant at first to try it but in my opinion people who try to do something original but inevitably fail due to these kind of issues still deserve to be rewarded. So I paid my dues and gave this game a go.

You play as an unnamed father who has traveled for a year by foot after massive earthquakes devastated the world leaving it in a never lifting dust cloud. His destination is Haventon; the town where his wife and daughter were when it all happened. The game starts as you arrive at Haventon where you need to find your way around, helping other survivors in an attempt to find your family. Along the way you team up with three characters; Henry, Mei and her mother Linda. The father records some of his actions using a cam-corder through which he addresses his wife and daughter, telling them of his progress. In between chapters we see the cam-corder sitting on a table with footage being watching by a woman, presumably one of the father’s kin.

I’m inclined to write about more aspects of ‘I am alive’ at a later date but now I’d like to touch on one particular topic; the ending.

 

— [Spoiler Alert: the ending will be discussed] —

 

Throughout the game you come across several people who, in some respect, you feel attached to and want to protect. It seems odd then that the game ‘rewards’ you after lighting the fireworks on top a sky-scraper ( in order to signal in a rescue boat to take Mei, her mother, and Henry out of the city ) with them having left their safe-zone without you. That’s not to say an escort mission would have been better but having them be gone by the time you get back feels strange; you are the one with all the weaponry, Henry is in a wheelchair and has no weapons we know of (next to the bow he gave us). It seems very irresponsible and downright backstabby that they would leave you behind like that. Now this is not even the main issue here but when you arrive at the docks it becomes apparent that; Henry has been taken hostage (he possibly knows where your wife and daughter may be, – your true objective – ), Mei (a little girl) has run off leaving her mother a shambles. You decide that she checks out the left side of the pier while you take the right.

One of the hairy situations you need to learn to master in I am alive

During this sequence you encounter many enemies and it may even feel like the greatest battle you’ve encountered yet. But through it all you survive and find Mei unharmed. You take her to her mother and they both leave without you as you wish to stay; to find Henry and ultimately your wife and daughter. This, to me, felt like I was about the embark on the final chapter of the game in which we safe Henry and end eventually with uncertainty; either Henry stays alive but you die but somehow you know your wife and daughter are okay. Or that Henry attempts to find them, giving them the cam-corder your are carrying around. This would account for the between-chapter cutscenes which show a (sad) girl rewatching your steps on said cam-corder.

But actually the game just ends there. You speak into the cam-corder saying something or other about how you will save Henry and find your wife and child. Then we zoom out of the cam-corder being watched by (presumably) your wife or daughter who starts sobbing implying your demise.

I can understand that due to budgeting reasons the game was made shorter than it was supposed to be, ending about half-way through. And actually it could have ended there and be fine. It would’ve been a hint towards a possible (but unlikely) sequel. But instead they closed the series (with the current main character that is) by sealing the deal on his death with the sobbing of the character watching.

The reason why I find this ending to be disappointing is because throughout the entire game I’ve been in charge of my character’s life. In a sense I’ve mastered the environment; I know how to traverse the dusty wasteland without suffocating, I am able to help other survivors, I know how to deal with bandits through means of intimidation and carefully placing my shots. And then after I’ve mastered it all the game ‘rewards’ me with the notion that my character is dead, just like that, no sacrificial scene, no tragic battle in the end, no dying for a good cause. He’s simply dead. Out of my control my character has been killed. Now one can argue this a base for a good horror story, and possibly a good horror ending but it is overshadowed by the fact that:

If you are, throughout the game, directly in control of a characters life.
He/She should not able to be killed outside of the player’s control.

Now I can imagine situations in which ignoring this is qualified; such as the ending of Fallout 3, which stirred up a lot of dust back then, but that in a sense is within the player’s own control. You decide to end your life there and then.

By ignoring this I think the ending of I am alive feels unrewarding by being unnecessarily definitive. I would have prefered the same ending but without the sobbing. That would have left a lot of things unanswered and may have enhanced the ‘why stop now’ feeling that it already stirs up but to me it would have been a better fitting ending to a game that left a lasting impression on me.

If like me you like game where you can lose yourself in the story, in the environment, in the characters. Then I suggest you try walking (not running) your way through I am alive’s dystopian streets of Haventon.

I am alive; a game I lost myself in for about 6 hours. I suggest you try it.

UDK: Disable Steamworks

If you want UDK to stop from telling Steam you’re running your game then disable the steam OnlineSubsystem with a simple INI file adjustment. Goto DefaultEngine.ini and add the following lines:

[OnlineSubsystemSteamworks.OnlineSubsystemSteamworks]
bEnableSteam=false

This should stop steam from notifying every person you know you’re running your game. I needed to disable Steam in UDK for a failed assert I got related to steam; unsure why it happens but it sure is annoying if it crashes your game while you don’t even use it.

Assertion Failed: Illegal termination of worker thread 'SteamFindServerThread'

Doing Research

I’ve done my share of research for previous projects. Usually deskresearch or some times real life investigations; like making our target audience participate in our ARG(Alternate Reality Game) and observing them as they go along as well as receiving feedback afterwards. But this was the first I’ve actually done research of such magnitude with this much information.

Initially I set out to better understand the working of creating a, somewhat, scientific paper; having well defined research questions, finding information, filtering information, and creating a final document, which is clear to most levels of expertise in the field, all while maintaining a clear overview of the project.

Defining your research questions proved quite difficult when you know, just about, what you want but you can’t fully encompass it in clear goals. This fact made the initial setup to the research take a lot longer than anticipated and was largely to blame to the fact that we, unknowingly, kept the research questions vague resulting in the gathering of information without a clear goal to strive towards. Later on these questions were ‘sharpened’ and this resulted in clearer goals. It’s become apparent that the research questions that were originally supplied in the graduation-document do not fully stand for what we want, so they will be probably rewritten. However they do show the overall picture we want to achieve and it is no way wrong to make your research-questions better as you go along.

Personally I like the gathering of information, a trait I suspect belongs to me, getting a better understanding in something I’m interested in gives a nice intrinsic motivation. Even now while we haven’t fully concluded our research part of our graduation I feel I’ve learned so much in the field of horror, and the subfields of things such as psychology, game-design, story-telling, etc, that it is already worth the time that we’ve invested in it. Now my only concern is that we might not be able to convey this fact to others, as the information we’ve picked up might not make it in the final document. But we’ve implemented, from the beginning, a system where we write small(not always) summaries of things we’ve read and find of importance which is already over 90 pages long, which is fun to see.

We’ve talked a lot with people about our document set-up and we’ve received some good advice on how to make it a more sensible whole and I personally enjoy watching a document grow into something comprehensible and understandable for other people.

Next to the deskresearch we’ve also done some practical research into physical reactions of people on horror. This means we’ve strapped a heart-monitor onto ourselves, put up cameras and recorded these during play-sessions of horror games. The information that came back gave us the clear impression that yes, there is a change of hear-rate during stressful moment but this does not (fully) show people’s psychological reaction. Do they find this truly disturbing or does the subject-matter make them feel uncomfortable. Also the system was prone to erroneous readings; picking up a cup of coffee spikes the heart-rate. These kinds of things you only find out when you try things out; comparing the footage to the heart-rate and examining the environment.

I also created a web-application to allow the examination of research data, which was a lot of fun to do. Also it added great value to the data which otherwise would be very difficult to interpret.

 

Say goodbye to your head, Leon.

 It must be said here though that Resident Evil 4 is, to me, more an action game than an actual horror.

So even though it is taking longer than expected, the value the research will have is immense. It’s quite satisfying to do research that you feel is important, relevant and helps you later on in development.