Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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
0
Question by R.Pete.G · Jul 23, 2015 at 05:24 PM · assetsserializationresources.loadserializedobject

Assets Returning Null

I've just started using ScriptableObject to store sets of data as Assets. I plan to manipulate this data a lot, so this looked like a good way to store / load serialised data.

What I've got so far works for creating the assets. I can use the Assets menu in Unity to add them, and the files that appear in my Assets directory include the right fields / variables.

The problem is, when I hit the Play button in the Game window to test out my code, they don't seem to be usable in the scene. if I try to Debug.Log them, I always get "null" returned and the following message:

"The referenced script on this Behaviour is missing! UnityEngine.Resources:Load(String, Type)"

Afterwards, when I select the assets, I get the following message in the Inspector panel (instead of the fields / variables):

"The associated script can not be loaded. Please fix any compile errors and assign a valid script."

Is the "referenced script" message the compile error that this is referring to? When I create new Team assets, the Script field in the Inspector panel just says "None (Mono Script)", so I'm not sure why this only becomes a problem afterwards.

I assume I've missed something fundamental about creating / loading assets, and I'm not accessing them properly. If I select an asset by clicking on it in the Project panel, and then press the Play button on the Game window, the asset works and still has its data afterwards. I'm guessing that highlighting / selecting an asset is somehow doing what I've missed in my functions.

Here's the code I'm using:

 public class Team extends ScriptableObject {
     
       public var TeamName : String;
       public var Rank : int;
     
 }
     
 public class TeamAsset {
     
       @MenuItem ('Assets/Create/Team')
       public static function create() {
     
         var newTeam : Team;
         var path : String = 'Assets/Resources/TeamData/Team.asset';
     
         newTeam = ScriptableObject.CreateInstance(Team);
         AssetDatabase.CreateAsset(newTeam, path);
         AssetDatabase.SaveAssets();
         AssetDatabase.Refresh();
     
       }
     
 }
 
 function loadTeam() {
 
     var thisTeam : Team = Resources.Load('TeamData/Team', Team) as Team;
     Debug.Log(thisTeam);
 
 }

In this (simplified, tidied up) example of my code, the function loadTeam just logs null and gives the "referenced script" missing error. When I double click it, I'm taken to the Resources.Load line in my code.

I'm clearly missing something when it comes to saving / loading assets, but hours of Googling has turned up nothing workable (partly because I'm not entirely sure how to phrase the problem).

Any help very much appreciated. Thanks!

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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

SerializedObject IntValue Multi Editing only applies to first object. 0 Answers

Does serializing objects use up more memory? 1 Answer

What's a fast serializer that works cross platform that can be used for saving/loading custom levels? 1 Answer

Created Assets not persisting after closing/opening editor 1 Answer

Display function parameters in inspector 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