Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by shaydenharley · Jan 11, 2019 at 02:30 PM · arraysnulltypes

Modify Custom Array Data

Good morning all,

I come to you today with an issue i'm hoping you can help with. Before we start i'd like to say that i've genuinely tried to fix this issue on my own but i just can't get it. So i have a main script named "MainButton" and within it i have this method

 public void TrainTroops (int NumberToTrain, int InterTroopID)
     {
         CurrentTroops = PlayerPrefs.GetInt(TroopManager.Instance.Troop_Types[InterTroopID].SaveDataName);
         ManageCurrency(TroopManager.Instance.Troop_Types[InterTroopID].TroopPrice, true);
         PlayerPrefs.SetInt(TroopManager.Instance.Troop_Types[InterTroopID].SaveDataName, CurrentTroops += NumberToTrain);
         UpdateTroopCounts();
     }

The above method is called when i button is pressed on. It's getting it's variables from another class which can be seen below;

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 
 public class TroopManager : MonoBehaviour {
 
 
     
     public static TroopManager Instance { get; }
 
     public TroopTypes[] Troop_Types = new TroopTypes[2];
 
     // Use this for initialization
     void Start () {
 
         // TroopTypes[]  Troop_Types = new TroopTypes[2];
 
         Troop_Types = new TroopTypes[2];
 
         //Create Troops Array     (ARRAY))
         Troop_Types[0].TroopDamage = 12;
         Troop_Types[0].TroopPrice = 20;
         Troop_Types[0].TroopName = "Mer-Tany";
         Troop_Types[0].TroopID = 0;
         Troop_Types[0].SaveDataName = "player_mert_count";
 
 
         Troop_Types[1].TroopDamage = 15;
         Troop_Types[1].TroopPrice = 20;
         Troop_Types[1].TroopName = "Knight";
         Troop_Types[1].TroopID = 1;
         Troop_Types[1].SaveDataName = "player_knight_count";
 
         Debug.Log("Troop Manager initilized");
 
     }
     
     // Update is called once per frame
     void Update () {
         
     }
 }

The above class is where the issue starts i believe as when executed their are no errors displayed in the console but it also doesn't print my debug line either. This class is creating an array using a type i created and is assigning them values. The type can be seen below

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class TroopTypes {
 
     //define all of the values for the class
     public int TroopHealth;
     public string TroopName;
     public int TroopPrice;
     public int TroopDamage;
     public int TroopID;
     public string SaveDataName;
 
     //define a constructor for the class
     public TroopTypes()
     {
 
        
 
 
 
     }
 }

So after showing you guys all that; let me explain the issue, when the button is clicked in the MainButton class to call the Method giving me problems i get a NullPointerException as seen below; Could you guys please take a look as i'm at a complete loss. Thanks everyone

alt text

error.png (33.0 kB)
Comment
Add comment
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

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

166 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

Related Questions

null array? 0 Answers

how do i create a array eg imBank(11) of type mytype: 2 Answers

No Vector3Int on version 5.6.5p1 2 Answers

C# ArrayList Accessing and RemoveAt? 0 Answers

Another Physics.OverlapSphere question 0 Answers


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