Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Adding the sound to the Modular First Person Controller

Discussion in 'Scripting' started by leccepen, Jul 28, 2023.

  1. leccepen

    leccepen

    Joined:
    Nov 7, 2021
    Posts:
    4
    Hi I'm trying to add the sound to the Modular First Person Controller downloaded from assetstore and I can't see the new created field in the inspector view
    Code (CSharp):
    1.  [SerializeField] private AudioSource jumpSound;
    What I'm doing wrong?
     

    Attached Files:

  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,718
    You need to actually look at the inspector for your FirstPersonController script. It is not visible in your screenshot. Is it even attached to your object?
     
  3. leccepen

    leccepen

    Joined:
    Nov 7, 2021
    Posts:
    4
    Hi,

    it is attached- pls see attached.
    I have even tried to add the sound other ways like create the AudioSource and AudioClip references but I get nullpointer
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. FirstPersonController.Update () (at Assets/ModularFirstPersonController/FirstPersonController/FirstPersonController.cs:333)
    3.  
    4.  
    I know that src object is empty (it is AudioSource scr) but I can't find the solution for adding the new component for it. There is no Add Component button on the script view...
     

    Attached Files:

    Last edited: Jul 28, 2023
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
  5. leccepen

    leccepen

    Joined:
    Nov 7, 2021
    Posts:
    4
    Please see below that the nullpointer is AudioSource reference ;)
    Is there any way to instantiate it over code or I need to add the Audio component over unity (which is impossible because I can't see the reference to AudioSource over Unity?
    I have tried to instatiate it with new keyword (I'm new with Unity but not new with coding) but Unity doesn't accept it.
    I guess there is some problem in this C# properties which I downloaded from Asset Store https://assetstore.unity.com/packages/3d/characters/modular-first-person-controller-189884.
     
    Last edited: Jul 28, 2023
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Then fix it!! Posting about it will not fix it!
     
  7. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,718
    This first person controller script you are using clearly has a custom editor. If you want to add fields to it you will need to modify the custom editor to include your field as well.
     
    leccepen likes this.
  8. leccepen

    leccepen

    Joined:
    Nov 7, 2021
    Posts:
    4
    Thank you very much it is some custom editor. I have deleted the part form custom editor and indeed it works fine now. Big thanks for help!