• 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 /
This question was closed Dec 12, 2016 at 12:18 AM by TabuuForteAkugun for the following reason:

Solved it myself. I had used a Playtest method on it in my global controller object, which has Awake on it. Causing it to try to load the clip data before it was initialized.

avatar image
0
Question by TabuuForteAkugun · Oct 18, 2016 at 10:48 PM · c#nullreferenceexceptionaudioclip

Unity can't load audioclip, but loads metadata from same class.

EDIT: Unity version: 5.4.2f1

Hi,

I have an issue with my AudioClip file. I created a container class specifically for music and its metadata for in-game display, including a float array to allow custom looped playback.

 My class structure is as follows.

 using UnityEngine;
 
 public class System_Music : MonoBehaviour
 {
     public AudioClip[] bgm_Clips;         // Actual song clip data.
     public float[] bgm_LoopPoints;        // Floats used for InfiniteBackgroundMusic.
     public string[] bgm_Titles;           // Song titles.
     /* public string[] bgm_Sources;          // Game sources.
     public string[] bgm_Type;             // "ORIGINAL", "REMIX", etc.
     public string[] bgm_Desc01;           // First line of description.
     public string[] bgm_Desc02;           // Second line of description.
     public string[] bgm_Desc03;           // Third line of description.
     public string[] bgm_Desc04;           // Final line of description.
     public Sprite[] bgm_Franchise;        // Game franchise icon for song.
     */
     public bool[] bgm_IsUnlocked;         // Unlock status for each individual song.
 
     // Singleton.
     public static System_Music bgm { get; set; }
 
     // Initialize the singleton.
     void Awake()
     {
         if(bgm == null)
         {
             bgm = this;
         }
         else if(bgm != this)
         {
             Destroy(gameObject);
         }
     }
 }

So I preloaded an song's AudioClip into my Clip array using the Inspector to test at runtime. I also typed some strings for metadata and a float for my loop point. The metadata and loop point display properly on the screen (a test OnGUI() for testing), but the AudioClip that is clearly present will not load and gives me a NullReferenceException, as if it's not loading it.

My audiosource is picked up fine by the main script, but whatever I do, it simply will not accept my AudioClip. It acts like it's not there. It plays in the Editor, it exists. So why isn't it loading at runtime?

I've attached a screenshot, 'cause I sure as hell can't see what I did wrong.

alt text

screenshot-727.png (60.2 kB)
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

  • Sort: 

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

244 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Not sure why i'm getting NullReferenceException 0 Answers

How to stop and re-start audio? 1 Answer

Weird Error With References 1 Answer

NullReferenceException when attempting to call a GameObject from within PointerEventData 1 Answer

How do I organize a list of GameObjects (OrderByDescending?) based on the property of an attached component? 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