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 Betina_art · Nov 01, 2021 at 01:29 PM · missingsystem.collections.generic

[SOLVED] Any List I make in this script becomes null, but it works fine with other scripts...

This is my first time asking a question here and it might look pretty silly after the fact, but I just can't figure out why my lists are null here:

I need a list that I can fill in with objects of a certain class from the editor. I've also tried changing the list to public/using get&set/instantiating the new list from start(), but nothing seems to work.


 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using Ink.Runtime;
 
 public class DialogueManager : MonoBehaviour
 {
     [SerializeField] private List<DialogueBox> dialogueBoxes = new List<DialogueBox>();
     [SerializeField] private List<InteractableData> speakers = new List<InteractableData>();
 
     void Start()
     {
 if (speakers != null)
         {
             Debug.Log("List of Interactable Data is null.");
         }
         if (dialogueBoxes != null)
         {
             Debug.Log("List of Dialogue Boxes is null.");
         }
         //Both checks return null,
 }



Meanwhile, I have another script where I do the same thing, even filling it with objects of a certain class through the editor and it works:


 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using TMPro;
 
 public class InteractionUIHandler : MonoBehaviour
 {
     [SerializeField] private List<InteractableName> interactableNames = new List<InteractableName>();
 }



Is there something I'm doing wrong or different here? There are no compiler errors too, And I've checked and rechecked that I populated the lists in the editor and there doesn't seem to be anything wrong with the code for InteractableData and DialogueBox either...

Comment
Add comment · Show 3
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 BigFluffyCookie · Nov 01, 2021 at 03:39 PM 3
Share

Do you know that your lists are null because of your debug logs or are you getting null reference errors when trying to access them? Because if its just the debug.logs then the issue is that you've mixed up '!=' and '==' in your if statements.

avatar image Betina_art BigFluffyCookie · Nov 02, 2021 at 12:23 AM 0
Share

Hi! Thanks for the reply. I know that it is null because I got null reference exceptions when I tried to access the list. Which I pinpointed to happen when I used foreach loops. A bunch of debug logs later and the list itself being null is where I got. I did check with an == null when using a long list of other debug checks to find where the error was. But that was before accessing the list. I can try it again at the start() in case there's a difference

avatar image Betina_art BigFluffyCookie · Nov 02, 2021 at 01:55 AM 1
Share

[UPDATE: Okay, me being kinda dumb and my checks were wrong, but after fixing that, I was able to find the real null reference error which happened to be just a mix-up in the order that made sure one variable was assigned a value before referencing it!]

0 Replies

· Add your reply
  • Sort: 

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

130 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

Related Questions

subfolders missing from standard assets folder (Unity 3) 3 Answers

Unity project weird behaviour - Scenes not opening / script links not working 1 Answer

MissingMethodException: Method not found- Error on fps script 1 Answer

Missing textures after import package 0 Answers

my hierarchy is gone 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