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 /
  • Help Room /
avatar image
1
Question by plugger22 · Sep 05, 2017 at 12:38 AM · scriptableobjectscriptable object

ScriptableObject Referencing

Hi,

I'm having a small conceptual problem with SO's. If I create an SO like thus...

 [CreateAssetMenu(menuName = "Node / Archetype")]
 public class NodeTypeArc : ScriptableObject
 {
     public string Test;
 }

I then generate, via the asset menu, a number of instance of this SO, eg. "Utility", "Corporate", "Government", "Research", which all appear in the Project view.

I understand that I can then drag and drop these instances across to a Monobehaviour script in the Inspector anywhere I have a public NodeTypeArc instance.

Q1: All good but is there a way to directly access the specific SO instances, eg. "Corporate", from code?

I realise I can easily do this...

 node.instance = ScriptableObject.CreateInstance<NodeTypeArc>();

but that doesn't get me the "Corporate" SO instance that I'm after.

Q2: Would I be correct in thinking that what I want could only be done by deriving from my NodeTypeArc SO class?, eg.

 public class Corporate : NodeTypeArc

and then doing this...

 node.instance = ScriptableObject.CreateInstance<Corporate>();

If somebody could point me in the right direction here it'd be appreciated.

Cheers,

Cameron

@plugger22

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by plugger22 · Oct 11, 2017 at 05:24 AM

I'll self answer this one.

AssetsDatabase.FindAssets does the job. The documentation is comphrensive but here's a quick snippet.

 @MenuItem("Test/FindAssetsUsingSearchFilter")
 static function FindAssetsUsingSearchFilter ()
 {
     // Find all assets labelled with 'concrete' :
     var guids = AssetDatabase.FindAssets ("l:concrete", null);
     for (var guid in guids)
         Debug.Log (AssetDatabase.GUIDToAssetPath(guid));
 
     // Find all Texture2Ds that have 'co' in their filename, that are labelled with 'concrete' or 'architecture' and are placed in 'MyAwesomeProps' folder
     var guids2 = AssetDatabase.FindAssets ("co l:concrete l:architecture t:texture2D", ["Assets/MyAwesomeProps"]);
     for (var guid in guids2)
         Debug.Log (AssetDatabase.GUIDToAssetPath(guid));
 }


By finding the SO, then getting it's asset path, you can load it directly from script.

Cheers, Cameron

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 Plasmajam · Oct 14, 2017 at 10:35 PM 0
Share

Were you able to use class Corporate directly in your code? If so, could you post code to show what you did?

avatar image johnbent · Aug 15, 2018 at 10:05 PM 0
Share

AssetDatabase will only work in the editor, not standalone builds. You could use Resources.Load, but Unity recommends only doing so for prototyping or small, rare instances, as the cost of loading from Resources does not scale.

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

115 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

Related Questions

Buttons to Scriptable objects 2 Answers

How do I place a custom tile? 1 Answer

How do I create tiles that I can add scripts to, and have players interact with? 0 Answers

I need a clean way to “cast” cards in a card game in Unity? 0 Answers

Scriptable Object Syntax in Javascript 1 Answer


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