Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by turbolek · Dec 03, 2019 at 12:39 PM · editorobjecteditor-scriptingserialization

How to assign object reference to ObjectField knowing the object's name?

I have a custom editor script with an ObjectField where I can assign my custom implementation of ScriptableObject. After I assign a scriptable object I get its name and store it so it persists when I reboot Unity. Knowing the object's name can I reassign the value to the ObjectField after rebooting Unity?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by KaspianR · Dec 03, 2019 at 01:20 PM

If the path in your project folder is persistent you can use that and the name of the object, otherwise I would store the path instead of the name since the name can always be received from the path in case you need it and that's just faster, better and easier in all ways and honestly, using a text object or most other methods really would probably suit you better. But if you still prefer to have it only save the name, here is a simple example of a script that loads a ScriptableObject by it's name (be it alot more resource intensive than storing the path itself):

 ScriptableObject so = (ScriptableObject) AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets("NAME OF SCRIPTABLE OBJECT")[0]));

Obviously replace the "NAME OF SCRIPTABLE OBJECT" with the actual name of the object and “ScriptableObject” with the name of your ScriptableObject class. Hope this helps you and good luck!

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image turbolek · Dec 03, 2019 at 01:50 PM 0
Share

Thanks, that does the trick. Also it turns out that Resources.Load works in the editor the same way it does in playmode, so i could be used as well.

avatar image KaspianR turbolek · Dec 03, 2019 at 02:24 PM 0
Share

Oh! Then I learnt something new too! Glad it worked out for you and good luck with the project!

avatar image
1

Answer by Bunny83 · Dec 03, 2019 at 01:16 PM

This makes no sense. The name of things are not necessarily unique in the first place. Also if you have a public / serialized field that references your scriptable object asset, that reference would be serialized as well if you created your "editor script" correctly. However since we don't know what your editor script does, how and where you show your object field and where you want to store that reference we can not really help you here.


To directly answer your question: No there's no built-in method to find an arbitrary asset by name. Apart from that when you build your game only used assets are included in the build. If the scriptable object is not (actually) referenced from an included scene (or a dependency of the scene) or placed inside the resources folder it won't be part of the build.


To me that sounds a lot like you are not really familiar with Unity's serialization system and how the editor works. Since you have a specific problem you should post all relevant information on that problem. You just came up with a strange workaround-approach which just doesn't work and asked how this can be done. Tell us what you actually want to do, what you currently do (include the relevant code, and where it's called from) and what exactly isn't working.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

171 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Editing prefab fields from custom editor that are not automatically serialized 0 Answers

Custom inspector variable resets automatically 1 Answer

Dynamic serialized fields based on enum 0 Answers

Storing data about an asset only in the editor 2 Answers

Help with Missing Monobehaviours and Asset Serialization? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges