• 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 Jun 29, 2020 at 12:11 PM by Sevotastic for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Sevotastic · Jun 29, 2020 at 12:03 PM · script error

System.int32 error?

Hi i am getting a little frustrated with this problem that unity is making: I have 3 different lists all of type Vector2 when the code runs after mousebutton0 is unclicked the script looks at what block is being placed and looks through the list position for that particular block and if it cant find the position in the list it will place the block and add the position to the list but then unity makes an error :

NullReferenceException: Object reference not set to an instance of an object DraggableBlockPlacer.CreateFloor (System.Int32 x, System.Int32 y)

and i legitimately have the exact same line of code for a different type of block and it works fine...

the code:

 List<Vector2> flooring, walls, foundation = new List<Vector2>();
     
      private void Update()
     {
             RunCode();
     }
     
     private void RunCode()
     {
     if (width >= 0 && height >= 0)
             {
                 for (int xAxis = 0; xAxis < width; xAxis++)
                 {
                     for (int yAxis = 0; yAxis < height; yAxis++)
                     {
                         
                         if (blockType == "Foundation") { CreateFoundation(xAxis, yAxis); }
                         if (blockType == "Walls") { CreateWalls(xAxis, yAxis); }
                         if (blockType == "Flooring") { CreateFloor(xAxis, yAxis); }
                         //else { Debug.LogError("No such block type : " + blockType); }
                         //Makes a positive (Bottom left to top right)
                     }
                 }
                 CodeReset();
             }
     }
     
     private void CreateFloor(int x, int y) 
         {
             
             Vector2 pos = new Vector2(x, y) + originPoint;
             if (foundation.Contains(pos)) //Is there a foundation there?
             {
                 Instantiate(block, pos, Quaternion.identity, transform);
                 flooring.Add(pos); // < this is the problem?
              }
         }
     
     //Exact same code for foundation
     
     private void CreateFoundation(int x, int y)
         {
             Vector2 pos = new Vector2(x, y) + originPoint;
             if (!foundation.Contains(pos))
             { 
                 Instantiate(block, pos, Quaternion.identity, transform);
                 foundation.Add(pos);
             }
         }

There's more to it but its a pretty big code.

Can someone plz help

Comment
Add comment · Show 1
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 Sevotastic · Jun 29, 2020 at 12:05 PM 0
Share

I seriously have no idea what the solution is

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Sevotastic · Jun 29, 2020 at 12:10 PM

Okay never-mind that is my fault i placed all the different list names under the same list. my bad :/

Comment
Add comment · Share
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

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

205 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

Related Questions

A Problem With A Script Of GUI.HorizontalSlider It Do not Move? 0 Answers

I have a problem with this script and an error appeared, does anyone know why? 0 Answers

How to reference this game object to another class 0 Answers

Can someone tell me what is wrong with this script? 1 Answer

Im having a problem with my C# code 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