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
0
Question by Jacho_Mendt · Sep 15, 2017 at 08:16 AM · editorscriptableobjectloadingstartup

Assets not loading correctly at startup

Hello,

I've created a series of assets, all deriving from a BaseNode abstract class that inherits from ScriptableObject. Everytime I open Unity and go in play mode, these assets don't load correctly. If I open a CustomEditor that loads those assets, it cannot find anything. But if I focus the asset in the project folder (either with left click or right click) and refresh the window, the object appears correctly and gets loaded in play mode AND every asset that is referenced by it works.

I have to do this everytime I open Unity.

Is there any reason why this happens, and how can I avoid having to click on every object? Thanks in advance!

Comment
Add comment · Show 2
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 Adam-Mechtley · Sep 15, 2017 at 08:44 AM 0
Share

Can you clarify what you mean when you say they "don't load correctly" in play mode? $$anonymous$$g., they are loaded and return null? They are loaded but report the wrong type (via e.g. GetType())? They are loaded but have the wrong data? Etc.

avatar image Jacho_Mendt Adam-Mechtley · Sep 15, 2017 at 10:11 AM 0
Share

No error message actually shows, but if I, for example, use a simple command as

Resources.FindObjectsOfTypeAll(typeof(Node));

without "refreshing" those scriptableObjects, the return array is empty, whereas if I "refresh" an asset by clicking on it, the same instruction now returns an array with that node and any other node it references. This also happens in edit mode, where I open an EditorWindow which displays all these assets. While at startup no asset is visible, after I click one it shows immediately

1 Reply

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

Answer by Adam-Mechtley · Sep 15, 2017 at 11:04 AM

The problem is that you should not use Resources.FindObjectsOfTypeAll() to retrieve assets, especially at run-time, because they may not necessarily end up in your build if you do it this way. In the Editor, these assets are loaded in lazily, which is why it works after you have clicked on them once.

Instead, your component should serialize references to the nodes directly, as this will cause them to be included in the build and be loaded when your component is loaded in the scene. For example:

 using System.Collections.Generic;
 using UnityEngine;

 class MyComponent : MonoBehaviour
 {
     // assign these in the Inspector
     [SerializeField]
     List<BaseNode> m_AllNodes = new List<BaseNode>();
 }

If you need to find these objects in your project at edit time (e.g., in some custom editor window) you should instead use AssetDatabase.FindAssets():AssetDatabase.FindAssets("t:BaseNode");

Comment
Add comment · Show 1 · 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 Jacho_Mendt · Sep 15, 2017 at 01:30 PM 0
Share

It works perfectly. Thank you!

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

137 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

Related Questions

Unity Editor Not Starting/Not Responding 1 Answer

Why is my editor taking so long to start up with internet connected? 0 Answers

because my game does not access my Scriptable Object 0 Answers

Unable to load Json to an object array 1 Answer

Resources.unload on scriptable object resets it's prefab references 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