Search Unity

Bug The settings won't reset when I click on the button.

Discussion in 'Scripting' started by PieridaeDev, Mar 15, 2022.

  1. PieridaeDev

    PieridaeDev

    Joined:
    Apr 5, 2020
    Posts:
    12
    Okay, so I'm trying to make it so that the player has the option to reset their settings, but whenever I click on the button, nothing happens (though I don't get any error messages, either), and I'm not sure if I'm being dumb again.

    Here's the scripts I used to make the menu.
    MenuController: https://pastebin.com/tqJ1gNy8
    LoadPrefs: https://pastebin.com/i68iWKci

    Below is the menu I made.
    Screenshot (796).png
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Place numerous Debug.Log statements throughout your ResetButton method to make sure your code is executing as expected and to print out your runtime variable values:

    https://forum.unity.com/threads/tips-for-new-unity-users.701864/#post-5057741
     
  3. PieridaeDev

    PieridaeDev

    Joined:
    Apr 5, 2020
    Posts:
    12
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes! Then observe the output and confirm that the values are what you expect. You also might want to place them before the associated methods too. In case those methods are changing the values.
     
  5. PieridaeDev

    PieridaeDev

    Joined:
    Apr 5, 2020
    Posts:
    12
    Okay, so now I'm getting this error: Screenshot (801).png
    Should I look at line 164 or is that not what the second line is referring to?
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes line 164, please share the code for that line. So it's one of your new Debug.Log statements? That's ok, it's showing that one of your objects is null. We just need to find out which one, then find out why.
     
  7. PieridaeDev

    PieridaeDev

    Joined:
    Apr 5, 2020
    Posts:
    12
    This is line 164: Screenshot (802).png
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    That isn't related to your Debug.Log statements, you are making other changes. You are using a capital letter on this object, the others have lowercase. Check your spelling.
     
  9. PieridaeDev

    PieridaeDev

    Joined:
    Apr 5, 2020
    Posts:
    12
    So do I change the other objects to have lowercase letters at the start? I'm honestly kinda stumped.
     
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    No, don't randomly start trying things. You need the same capitalization and spelling as the definition of the objects. Where do you define these objects? Show the code, you need to keep the naming the same.
     
  11. PieridaeDev

    PieridaeDev

    Joined:
    Apr 5, 2020
    Posts:
    12
    I've updated the MenuController script. You can find the pastebin link near the top of the post.
     
  12. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Did you copy this code from somewhere? You have this, so QualityDropdown is null unless you set it to something before you try to use it.

    [SerializeField] private TMP_Dropdown QualityDropdown;

    Why do you have it a SerializeField? Just checking, are you sure you don't want to make this public like the other:

    public TMP_Dropdown resolutionDropdown;
     
  13. PieridaeDev

    PieridaeDev

    Joined:
    Apr 5, 2020
    Posts:
    12
    I was watching a tutorial for this (this tutorial, to be more specific: https://www.youtube.com/watch?v=Cq_Nnw_LwnI), though I did take some creative liberties and made the three options menus showcased in it into one large one.
     
  14. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Look at 1:11:45 where they add the qualityDropdown into the Inspector. Typically when following tutorials, you get the code working exactly as demonstrated, THEN make your changes.
     
  15. PieridaeDev

    PieridaeDev

    Joined:
    Apr 5, 2020
    Posts:
    12
    Okay, so I did everything you said, and I'm still getting that error. Here, I'll update the MenuController script on pastebin again just to show you.
     
  16. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    That's ok, I believe you! And you got the demo from the video working with no changes? Again, personally I would make the object public and drop it into the Inspector, I'm not completely familiar with SerializeField. If you are not familiar either, then you should not use it. Generally you should not use code that you don't understand. Please show a screenshot of the QualityDropdown in the Inspector like in the video.
     
  17. PieridaeDev

    PieridaeDev

    Joined:
    Apr 5, 2020
    Posts:
    12
    Here you go:
    Screenshot (807).png Screenshot (805).png Screenshot (804).png
     

    Attached Files:

  18. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Again, look at 1:11:45 where they add the qualityDropdown into the Inspector. I don't see that in your screenshot. To be clear, what are you working on now? Your code changes, or getting the original video code working? Or did you have it working, and now adding your changes? Did you make the object public as I suggested? Otherwise, time to go learn about SerializeField!
     
  19. PieridaeDev

    PieridaeDev

    Joined:
    Apr 5, 2020
    Posts:
    12
    Okay, so turns out I just needed to add the dropdown to the MenuController object.