- Home /
2 Errors in script for the editor
I took this script from the Unity website to mess around with and copy pasted it and it is not working and gave me 2 errors (I dit not modify it).
/// C# Example
// Simple script that saves frames from the Game View when on play mode
//
// You can put later the frames togheter and create a video.
// Note: The frames are saved next to the Assets folder.
using UnityEngine;
using UnityEditor;
public class SimpleRecorder : EditorWindow {
string fileName = "FileName";
string status = "Idle";
string recordButton = "Record";
bool recording = false;
float lastFrameTime = 0.0f;
int capturedFrame = 0;
[MenuItem ("Example/Simple Recorder")]
static void Init () {
SimpleRecorder window =
(SimpleRecorder)EditorWindow.GetWindow(typeof(SimpleRecorder));
}
void OnGUI () {
fileName = EditorGUILayout.TextField ("File Name:", fileName);
if(GUILayout.Button(recordButton)) {
if(recording) { //recording
status = "Idle...";
recordButton = "Record";
recording = false;
} else { // idle
capturedFrame = 0;
recordButton = "Stop";
recording = true;
}
}
EditorGUILayout.LabelField ("Status: ", status);
}
void Update () {
if (recording) {
if (EditorApplication.isPlaying && !EditorApplication.isPaused){
RecordImages();
Repaint();
} else
status = "Waiting for Editor to Play";
}
}
void RecordImages() {
if(lastFrameTime < Time.time + (1/24f)) { // 24fps
status = "Captured frame " + capturedFrame;
Application.CaptureScreenshot(fileName + " " + capturedFrame + ".png");
capturedFrame++;
lastFrameTime = Time.time;
}
}
}
(source: http://docs.unity3d.com/Documentation/ScriptReference/EditorWindow.Update.html)
the ERROS: Instance of SimpleRecorder couldn't be created because there is no script with that name. UnityEditor.EditorWindow:GetWindow(Type) SimpleRecorder:Init() (at Assets/Editor/BlackCoreEditorWindow.cs:16)
NullReferenceException: Object reference not set to an instance of an object UnityEditor.EditorWindow.GetWindow (System.Type t, Boolean utility, System.String title, Boolean focus) (at C:/BuildAgent/work/7535de4ca26c26ac/Editor/MonoGenerated/Editor/EditorWindow.cs:418) UnityEditor.EditorWindow.GetWindow (System.Type t) (at C:/BuildAgent/work/7535de4ca26c26ac/Editor/MonoGenerated/Editor/EditorWindow.cs:402) SimpleRecorder.Init () (at Assets/Editor/BlackCoreEditorWindow.cs:16)
How do I fix this?
In the project view, is the relevant script also called SimpleRecorder?
Answer by DaveA · Aug 12, 2013 at 10:57 PM
The first error tells me you didn't call the file SimpleRecorder.cs
Fix that and the second one will probably go away too.