-1
\$\begingroup\$

How can I get the name of a scriptable object, same way I would a game object gameObject.name?

I've tried:

object.name
scriptableObject.name
ScriptableObject.name
name
this.name

//String GetName()
WorldObjectData obj = ScriptableObject.CreateInstance<WorldObjectData>();
SerializedObject serializedObject = new SerializedObject(obj);
return serializedObject.FindProperty("m_name");

I can see that ScriptableObject extends Object, which has the .name attribute. But cant access it.

\$\endgroup\$
2
\$\begingroup\$

Presumably you started by trying the most obvious thing, object.name, the same way you would with a game object?

They both inherit from UnityEngine.Object which is where the .name field is defined.

\$\endgroup\$
  • \$\begingroup\$ Yes, this does not work, or Im doing it wrong \$\endgroup\$ – Majs Aug 10 '20 at 13:11
  • \$\begingroup\$ You're doing it wrong. Edit your question to show in detail what you're doing, what outcome you expect, and what outcome you're getting instead. \$\endgroup\$ – DMGregory Aug 10 '20 at 13:11
  • \$\begingroup\$ Okay, Edited, thanks \$\endgroup\$ – Majs Aug 10 '20 at 13:14
  • \$\begingroup\$ I see the issue now I think, Im using a field variable name, which hides Object.name \$\endgroup\$ – Majs Aug 10 '20 at 13:17
  • \$\begingroup\$ This is why it's important to show what you've tried in its full context in your question. ie. Your first post should have included the whole script that exhibits the problem, so we could see and point out the member shadowing the name field. \$\endgroup\$ – DMGregory Aug 10 '20 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.