- Home /
The question is answered, right answer was accepted
"Object reference not set to an instance of an object" but it is.
Code its self pretty basic issue is once i bake one bundle any other GMC can not be baked pops up error of
NullReferenceException: Object reference not set to an instance of an object BuildMod.OnGUI () (at Assets/Editor/BuildMod.cs:32)
Here is code I'm working with few friends on this as well if i figure out ill post my findings
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class BuildMod : EditorWindow
{
GMC GMC_Data;
[MenuItem("Assets/Cook Mod")]
static void BuildAllAssetBundles()
{
EditorWindow.GetWindow(typeof(BuildMod));
}
void ClearData()
{
AssetDatabase.RemoveUnusedAssetBundleNames();
EditorWindow.GetWindow(typeof(BuildMod)).Close();
}
private void OnGUI()
{
GMC_Data = EditorGUILayout.ObjectField(GMC_Data, typeof(GMC), true) as GMC;
if (GMC_Data != null)
{
if (GUILayout.Button("Cook"))
{
AssetImporter.GetAtPath("Assets/Mods/" + GMC_Data.Name + "/" + GMC_Data.Name + ".asset").SetAssetBundleNameAndVariant(GMC_Data.Name, "GMC");
BuildPipeline.BuildAssetBundles("Assets/StreamingAssets/" + GMC_Data.name, BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.StandaloneWindows64);
AssetImporter.GetAtPath("Assets/Mods/" + GMC_Data.Name + "/" + GMC_Data.Name + ".asset").SetAssetBundleNameAndVariant("", "");
ClearData();
}
}
}
}
Answer by darkal · Aug 17, 2019 at 10:48 PM
I was able figure it out I was using variable GMC.Name instead of GMC.name which is name of the asset by replace Name with name the issue has been fixed and now works everytime without issue.
Answer by thehiveissocial · Aug 17, 2019 at 10:13 PM
Perhaps putting GMC_Data = EditorGUILayout.ObjectField(GMC_Data, typeof(GMC), true) as GMC; inside of the Start function instead of OnGUI function would work? I'm guessing the error is coming from that line of code I recommended to put in start since the other lines do a if not null check. I'm not really familiar with GUI but figured it wouldn't hurt trying to help.
No it has use the OnGUI as it creates a variable inside of a window same way as in the inspector everything works fine tell it runs
AssetDatabase.RemoveUnusedAssetBundleNames();
And i require that part to remove the unused bundle names other wise they get messy
Follow this Question
Related Questions
Error after building a bundle,Error while creating a bundle 0 Answers
An instance of type "x" is required to access non-static variable "y" 2 Answers
When looping through assetbundle assetdatabase how do you reference a material object 0 Answers
AssetBundle Error 1 Answer
The file 'MemoryStream' is corrupted! 6 Answers