Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 sloankelly · May 23, 2013 at 08:07 PM · c#serializationnull

Object says it's null, but on inspecting it seems to have the correct value

Hi, I have a derived class that I'm serializing. If I check the value in code, it says it's null. But if I inspect the value it actually has a value. See attached image. Can anyone tell me what's causing this?

alt text

As you can see, the if-check succeeds and the for-loop is short-circuited with a 'continue', however 'item' actually has a value, the value that I'd expect it to have.

 [Serializable]
 public class ScriptableActionsAsset : NarrationScriptableObject
 {
     [SerializeField]
     public ScriptableActionItem[] Items;
 }

 [Serializable]
 public class PlayAudioActionItem : ScriptableActionItem
 {
     [SerializeField]
     public AudioClip pathToAudioClip;
 }

 [Serializable]
 public class ScriptableActionItem : ScriptableObject
 {
 }

I realise that the [Serializable] attributes are a bit redundant, but I had them in initially and haven't removed them yet. The ScriptableActionItem and NarrationScriptableObject contains methods but no data, they both extend ScriptableObject.

The ScriptableActionsAsset is a property on a MonoBehaviour. The Start() method of MonoBehaviour (attached to a GO) runs the following method:

 public void ConvertActionItems(GameObject target, IList items)
 {
     foreach(ScriptableActionItem item in items)
     {
         if (item == null)
         {
             continue;
         }
         
         var scriptableItem = item.ToAction(target);
         Actions.Add(scriptableItem);
     }
 }



inspector.png (5.7 kB)
Comment
Add comment · Show 7
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 Tomer-Barkan · May 23, 2013 at 09:18 PM 0
Share

am I blind or does the inspector say the value of item is {null}?

avatar image sloankelly · May 23, 2013 at 10:05 PM 0
Share

Yes, but... it says it has a base and the property (pathToAudioClip) is correct and is a member of the class I'm expecting. The class itself extends from ScriptableActionItem (my own class) and that extends from ScriptableObject.

avatar image KiraSensei · May 23, 2013 at 10:06 PM 0
Share

item is null ...

Everything after that is not relevant for you, you only check the item value.

avatar image sloankelly · May 23, 2013 at 10:09 PM 0
Share

I don't understand why it's null but I can see the values I'm expecting though. If I go to the immediate window and type 'item == null' (without quotes) it returns false. Similarly, if I type item.pathToAudioClip I get the value I expect.

avatar image KiraSensei · May 23, 2013 at 10:12 PM 0
Share

If you are sure that "item" is valuated, you'll need to show us more of your code, to check what is the real value.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Lovrenc · Aug 09, 2013 at 11:23 PM

Item is null!

That value you see simply tells you the TYPE OF YOUR VARIABLE.

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

17 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

Related Questions

Distribute terrain in zones 3 Answers

Why is my C# array of objects fully populated when some of them should be null? 3 Answers

Multiple Cars not working 1 Answer

Cannot convert object[] to Vector3[] 2 Answers

Serialization - Variables won't change on original construction 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