The Name 'GUID' does not exist in the current context
I am using the Unity tutorials to make a project. When I go to build the game, I get two errors both from the same script telling me "The Name 'GUID' does not exist in the current context", and it is really frustrating. This is not anything that the standard assets were able to fix when I tried, but I just need help. Thank you, everyone! As well as this, the script it was in is really messy and all in one line. I'm not sure how that happened I didn't do that.
using System;
using UnityEditor;
using UnityEngine;
using System.Linq;
[ExecuteInEditMode]
[DisallowMultipleComponent]
[AddComponentMenu("")]
public class SceneObjectGUIDComponent : MonoBehaviour
{
[SerializeField] private string m_Id;
[NonSerialized] private bool m_Registered;
public string id
{
get { return m_Id; }
}
public void Awake()
{
if (!Application.isEditor)
Destroy(this);
if (string.IsNullOrEmpty(m_Id))
{
m_Id = GUID.Generate().ToString();
}
else
{
var components = UnityEngine.Object.FindObjectsOfType<SceneObjectGUIDComponent>();
if (components.Any(c => c.m_Id == m_Id && c != this))
{
m_Id = GUID.Generate().ToString();
}
}
hideFlags |= HideFlags.HideInInspector;
Register();
}
private void Register()
{
if (m_Registered || !Application.isEditor)
return;
SceneObjectGUIDManager.instance.Register(this);
m_Registered = true;
}
void OnValidate()
{
// Register in OnValidate becuase Awake in not called on domain reload in edit mode
Register();
}
void OnDestroy()
{
if (SceneObjectGUIDManager.IsInitiated)
SceneObjectGUIDManager.instance.Deregister(this);
}
}
Answer by stuartmcroberts · Apr 04, 2019 at 11:16 PM
GUID is part of the UnityEditor name space and is not available in android try using System.Guid instead.
Your answer
![](https://koobas.hobune.stream/wayback/20220612175935im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how can i fix building game? 1 Answer
I can't build my project, how can I fix it? 3 Answers
2 error messages i can't seem to fix (CS0101 and CS0111) 1 Answer
IL2CPP Windows Build 0 Answers
material.SetColor causing Hidden/InternalErrorShader 1 Answer