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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[Solved]Unknown problem with scripts

Discussion in 'Scripting' started by Svarr, Dec 22, 2015.

  1. Svarr

    Svarr

    Joined:
    Dec 20, 2015
    Posts:
    22
    First of all I apologise for the vague title.

    I'm having multiple issues with a scene. It contains a button to get back to the menu and two ScrollRect's ("Library" and "Deck")whose contents ("LibraryContent" and "DeckContent") get created dynamically with prefabs (modified selectables). I got it working somehow, using VerticalLayoutGroup components.
    Yesterday I created the Menu Scenes and connected everything with buttons and when I tried it I got these issues:
    1. The contents don't get populated anymore until I enter the scene a third time. But then, when I click on one of the entries, I get a missing reference exception (at first for a text gameobject until I moved the lines of code that keep it updated to another method, now I get an exception with the type 'DeckContentScript')
    MissingReferenceException: The object of type 'DeckContentScript' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    DeckContentScript.UpdateContentHeight () (at Assets/Scripts/DeckContentScript.cs:69)
    DeckContentScript.DeletePrefabs (System.Collections.Generic.List`1 goL) (at Assets/Scripts/DeckContentScript.cs:62)
    DeckContentScript.DoReset () (at Assets/Scripts/DeckContentScript.cs:32)
    EventManagerScr.TriggerChange () (at Assets/Scripts/EventManagerScr.cs:12)
    LibrarySlotScript.OnPointerDown (UnityEngine.EventSystems.PointerEventData eventdata) (at Assets/Scripts/LibrarySlotScript.cs:104)
    UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerDownHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:38)
    UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerDownHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269)
    UnityEngine.EventSystems.EventSystem:Update()

    2. This may be unrelated, but in the GameMenu Scene, to which I go when I leave this scene, a button that is supposed to enable a GUI.window (which asks for confirmation and loads the MainMenu Scene afterwards) loads this scene instead - instantly. (I made sure that the button called the right method and that the Scene name string in that method is spelled correctly)

    Since the MissingReferenceException is of no use, I have absolutely no idea what could cause the issue.
    Another thing: I removed the VerticalLayoutGroup components and positioned the content via script again, hoping this would solve the problem.

    The Scripts:
    [removed, since the issues are solved]
     
    Last edited: Jan 6, 2016
  2. Svarr

    Svarr

    Joined:
    Dec 20, 2015
    Posts:
    22
    Update: 2. The scene is no longer instantly loaded, the confirmation window now shows. But no matter which choice I make, I get returned to this scene.
    Whatever I do in this menu, I get thrown right into the DeckBuilder Scene. This happens both in the Editor and in the built application regardless of whether I have been there before or not.
     
    Last edited: Dec 22, 2015
  3. Svarr

    Svarr

    Joined:
    Dec 20, 2015
    Posts:
    22
    The two issues were unrelated.
    I solved the first one, but sadly forgot how.

    The second issue was caused by the 'click through-ability' of dynamically created gui elements. I solved this with using a prefab for pop ups.