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
6
Question by brentrkendall · Aug 11, 2017 at 07:20 AM · scriptableobjectscriptable object

Why "the associated script can not be loaded" for some Scriptable Objects?

I created several scriptable objects that I use in a finite-state-machine. They all work fine except about every 4th or 5th "play" (or whenever I close and reopen my project) the same 3 scriptable objects are no longer valid. Their "script" slot is populated with "None (Mono Script)", and the warning underneath reads, "The associated script can not be loaded. Please fix any compile errors and assign a valid script." As a result, I have to recreate these 3 objects periodically. They compile fine, and--aside from their names--are identical to a few other scriptable objects in my solution that work fine and never disappear. So, I'm confused. Anybody know what would cause this, so I can stop recreating these 3 objects every 4-5 test runs of my game? Thanks!

Here's a screenshot of the error:

alt text

Here's the code of one of the 3 scriptable objects:

alt text

error.jpg (112.6 kB)
script.jpg (59.6 kB)
Comment
Add comment · Show 6
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 brentrkendall · Jul 29, 2017 at 12:24 AM 0
Share

I should add that I'm using these scriptable objects as Pluggable AI objects. I'm noticing the 3 troublesome objects almost always disappear on reopening Unity, and they also disappear whenever a scene changes in unity, and they even sometimes disappear every 4-5 runs of my game in unity. The files/scripts themselves still exist (so I don't have to rewrite the scripts), but they are no longer associated with the Pluggable AI object as shown in the screenshot above (where it says "None ($$anonymous$$ono Script)" where it should say the name of my object, such as "DistributeCardsToOpponent3CompleteDecision".

avatar image CraigGraff · Jul 29, 2017 at 05:40 AM 0
Share

Are you using the ScriptableObjects as runtime-modifiable assets or creating instances of them at runtime?

avatar image brentrkendall CraigGraff · Aug 11, 2017 at 06:53 AM 0
Share

I'm not creating instances at runtime. They are Pluggable AI scriptable assets that exist prior to runtime, and then I just select which ones I want to execute in a given state via the Inspector. It's the exact same process that $$anonymous$$att Shell used in his Unity Live Training demo called "Pluggable AI With Scriptable Objects", which you can find here: https://www.bing.com/videos/search?q=unity+plugable+ai+with+scriptable+objects&&view=detail∣=2F1465C1BD0149A3B3962F1465C1BD0149A3B396&rvsmid=8D607F5442D905DF8B8D8D607F5442D905DF8B8D&fsscr=0&FOR$$anonymous$$=VDRVRV.

avatar image a161803398874 · Jul 29, 2017 at 06:22 AM 0
Share

Show console errors please

avatar image brentrkendall · Jul 30, 2017 at 02:23 AM 0
Share

alt text

The error is "NullReferenceException: Object reference not set to an instance of an object State.DoEnterActions (.StateController controller) (at Assets/PluggableAI/Scripts/State.cs:20)". It's because the reference to the script behind the scriptable object has been broken, which means the "Decision" element in my State object is "None (Decision)" ins$$anonymous$$d of "Distribute Cards to Opponent 3" as it should be (see screenshot). So, Unity doesn't think there's an object. I have to recreate the object, then drag it back into the "Decision" element box in my state in the Inspector. I have to repeatedly do this every time the scriptable object gets removed (as shown in my original screenshot above). Hopefully that makes sense.

I've also included a screenshot of the line of code that throws the error, because it's loaded a null value into my "Actions" array, so it can't read it at line 20. But that's not the root-problem. That line of code works once I've recreated my scriptable object. $$anonymous$$y question is why does my scriptable object keep resetting to "None ($$anonymous$$ono Script)" every few runs of my program, causing all these problems until I recreate it?!

alt text

error.jpg (253.8 kB)
capture.jpg (60.8 kB)
avatar image Bunny83 brentrkendall · Jul 30, 2017 at 02:38 AM 0
Share

If you want to update / improve your question, you should edit your question. You can edit your question from the cog-wheel menu at the top right of your question.

1 Reply

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

Answer by Bunny83 · Jul 30, 2017 at 02:47 AM

It's hard to tell what could be the reason, however common problems are:

  • your scriptable object is not located in it's own script file but placed in a file with multiple other classes

  • the name of the script file does not match the actual class name.

Your project looks quite organised so i would doubt the first point. So most likely the file name doesn't match the class name. Note by "file name" i mean the script file (*.cs) not your scriptable object asset file.

ps: If you have many classes you may want to start using namespaces. Unity does support namespaces for quite some time now.

Also next time it would be better to include code samples as text and mark it as code instead of posting images. It just makes it more difficult for us to read and refer to your code.

Comment
Add comment · Show 4 · 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 brentrkendall · Jul 30, 2017 at 04:46 PM 0
Share

Yes, that's it! THAN$$anonymous$$ YOU! The problem was a mismatch between the names of the classes and the file names. I inadvertently had an extra "e" in the those 3 titles that escaped my eye (e.g., RepeateDistributionOfCardsCompleteDecision).

avatar image rudylee94 · Sep 03, 2018 at 01:28 AM 0
Share

Very thanks ,you help me a lot.

avatar image AntonInsane · Mar 09, 2019 at 02:21 PM 0
Share

Helped me too, thanks.

avatar image henryxiu2005 · Jun 30, 2020 at 02:26 AM 0
Share

It works for me too! Thank you! $$anonymous$$uch appreciated!

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

74 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

Related Questions

Load JSON Scriptable Object and Prefabs 1 Answer

Is ScriptableObject suitable for fast data write/access? 1 Answer

How to Reuse Script on Enemies - Please Help! 2 Answers

Scriptable Objects not present in Built Version 1 Answer

Question about NPC schedules and Scriptable Objects. 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