• 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 CodeMateo · Oct 20, 2022 at 06:18 AM · save datanull reference exceptionbinarywriter

NullReferenceException in Save System

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 [System.Serializable]
 public class SaveSystem
 {
     public int playerCountry { get; set; }
 
     public int FranceAIGold { get; set; }
     public int SpainAIGold { get; set; }
     public int PortugalAIGold { get; set; }
     public int UKAIGold { get; set; }
     public int CRAIGold { get; set; }
     public int MoroccoAIGold { get; set; }
     public int AlgeriaAIGold { get; set; }
     public int TunisAIGold { get; set; }
     public int SardiniaAIGold { get; set; }
     public int SicilyAIGold { get; set; }
     public int NaplesAIGold { get; set; }
     public int LuccaAIGold { get; set; }
     public int ItalyAIGold { get; set; }
     public int HelvetiaAIGold { get; set; }
     public int AustriaAIGold { get; set; }
     public int OttomanAIGold { get; set; }
     public int MontenegroAIGold { get; set; }
     public int PrussiaAIGold { get; set; }
     public int WarsawAIGold { get; set; }
     public int RussiaAIGold { get; set; }
     public int SwedenAIGold { get; set; }
     public int NorwayAIGold { get; set; }
     public int FranceAIPopulation { get; set; }
     public int SpainAIPopulation { get; set; }
     public int PortugalAIPopulation { get; set; }
     public int UKAIPopulation { get; set; }
     public int CRAIPopulation { get; set; }
     public int MoroccoAIPopulation { get; set; }
     public int AlgeriaAIPopulation { get; set; }
     public int TunisAIPopulation { get; set; }
     public int SardiniaAIPopulation { get; set; }
     public int SicilyAIPopulation { get; set; }
     public int NaplesAIPopulation { get; set; }
     public int LuccaAIPopulation { get; set; }
     public int ItalyAIPopulation { get; set; }
     public int HelvetiaAIPopulation { get; set; }
     public int AustriaAIPopulation { get; set; }
     public int OttomanAIPopulation { get; set; }
     public int MontenegroAIPopulation { get; set; }
     public int PrussiaAIPopulation { get; set; }
     public int WarsawAIPopulation { get; set; }
     public int RussiaAIPopulation { get; set; }
     public int SwedenAIPopulation { get; set; }
     public int NorwayAIPopulation { get; set; }
     public int FranceAIMaterial { get; set; }
     public int SpainAIMaterial { get; set; }
     public int PortugalAIMaterial { get; set; }
     public int UKAIMaterial { get; set; }
     public int CRAIMaterial { get; set; }
     public int MoroccoAIMaterial { get; set; }
     public int AlgeriaAIMaterial { get; set; }
     public int TunisAIMaterial { get; set; }
     public int SardiniaAIMaterial { get; set; }
     public int SicilyAIMaterial { get; set; }
     public int NaplesAIMaterial { get; set; }
     public int LuccaAIMaterial { get; set; }
     public int ItalyAIMaterial { get; set; }
     public int HelvetiaAIMaterial { get; set; }
     public int AustriaAIMaterial { get; set; }
     public int OttomanAIMaterial { get; set; }
     public int MontenegroAIMaterial { get; set; }
     public int PrussiaAIMaterial { get; set; }
     public int WarsawAIMaterial { get; set; }
     public int RussiaAIMaterial { get; set; }
     public int SwedenAIMaterial { get; set; }
     public int NorwayAIMaterial { get; set; }
 
     public int FNWcontroller { get; set; }
     public int FNWCavalry { get; set; }
     public int FNWInfantry { get; set; }
     public int FNWArtillery { get; set; }
     public int FSEcontroller { get; set; }
     public int FSECavalry { get; set; }
     public int FSEInfantry { get; set; }
     public int FSEArtillery { get; set; }
     public int FNEcontroller { get; set; }
     public int FNECavalry { get; set; }
     public int FNEInfantry { get; set; }
     public int FNEArtillery { get; set; }
     public int FSWcontroller { get; set; }
     public int FSWCavalry { get; set; }
     public int FSWInfantry { get; set; }
     public int FSWArtillery { get; set; }
 
     public int SNcontroller { get; set; }
     public int SNCavalry { get; set; }
     public int SNInfantry { get; set; }
     public int SNArtillery { get; set; }
     public int SScontroller { get; set; }
     public int SSCavalry { get; set; }
     public int SSInfantry { get; set; }
     public int SSArtillery { get; set; }
 
     public int PNcontroller { get; set; }
     public int PNCavalry { get; set; }
     public int PNInfantry { get; set; }
     public int PNArtillery { get; set; }
     public int PScontroller { get; set; }
     public int PSCavalry { get; set; }
     public int PSInfantry { get; set; }
     public int PSArtillery { get; set; }
 
     public int INcontroller { get; set; }
     public int INCavalry { get; set; }
     public int INInfantry { get; set; }
     public int INArtillery { get; set; }
     public int IScontroller { get; set; }
     public int ISCavalry { get; set; }
     public int ISInfantry { get; set; }
     public int ISArtillery { get; set; }
     public int EEcontroller { get; set; }
     public int EECavalry { get; set; }
     public int EEInfantry { get; set; }
     public int EEArtillery { get; set; }
     public int EWcontroller { get; set; }
     public int EWCavalry { get; set; }
     public int EWInfantry { get; set; }
     public int EWArtillery { get; set; }
     public int Scontroller { get; set; }
     public int SCavalry { get; set; }
     public int SInfantry { get; set; }
     public int SArtillery { get; set; }
 
     public int CNcontroller { get; set; }
     public int CNCavalry { get; set; }
     public int CNInfantry { get; set; }
     public int CNArtillery { get; set; }
     public int CScontroller { get; set; }
     public int CSCavalry { get; set; }
     public int CSInfantry { get; set; }
     public int CSArtillery { get; set; }
 
     public int MEcontroller { get; set; }
     public int MECavalry { get; set; }
     public int MEInfantry { get; set; }
     public int MEArtillery { get; set; }
     public int MWcontroller { get; set; }
     public int MWCavalry { get; set; }
     public int MWInfantry { get; set; }
     public int MWArtillery { get; set; }
     public int AEcontroller { get; set; }
     public int AECavalry { get; set; }
     public int AEInfantry { get; set; }
     public int AEArtillery { get; set; }
     public int ACcontroller { get; set; }
     public int ACCavalry { get; set; }
     public int ACInfantry { get; set; }
     public int ACArtillery { get; set; }
     public int AWcontroller { get; set; }
     public int AWCavalry { get; set; }
     public int AWInfantry { get; set; }
     public int AWArtillery { get; set; }
     public int TNcontroller { get; set; }
     public int TNCavalry { get; set; }
     public int TNInfantry { get; set; }
     public int TNArtillery { get; set; }
     public int TScontroller { get; set; }
     public int TSCavalry { get; set; }
     public int TSInfantry { get; set; }
     public int TSArtillery { get; set; }
 
     public int SACcontroller { get; set; }
     public int SACCavalry { get; set; }
     public int SACInfantry { get; set; }
     public int SACArtillery { get; set; }
 
     public int SICcontroller { get; set; }
     public int SICCavalry { get; set; }
     public int SICInfantry { get; set; }
     public int SICArtillery { get; set; }
 
     public int NEcontroller { get; set; }
     public int NECavalry { get; set; }
     public int NEInfantry { get; set; }
     public int NEArtillery { get; set; }
     public int NWcontroller { get; set; }
     public int NWCavalry { get; set; }
     public int NWInfantry { get; set; }
     public int NWArtillery { get; set; }
     public int NNcontroller { get; set; }
     public int NNCavalry { get; set; }
     public int NNInfantry { get; set; }
     public int NNArtillery { get; set; }
 
     public static SaveSystem fromAI(countries countries)
     {
         return new SaveSystem
         {
             playerCountry = (int)GameObject.Find("information").GetComponent<countries>().playerCountry,
 
             FranceAIGold = (int)GameObject.Find("information").GetComponent<countries>().franceGold,
             SpainAIGold = (int)GameObject.Find("information").GetComponent<countries>().spainGold,
             PortugalAIGold = (int)GameObject.Find("information").GetComponent<countries>().portugalGold,
             UKAIGold = (int)GameObject.Find("information").GetComponent<countries>().UKGold,
             CRAIGold = (int)GameObject.Find("information").GetComponent<countries>().CRGold,
             MoroccoAIGold = (int)GameObject.Find("information").GetComponent<countries>().moroccoGold,
             AlgeriaAIGold = (int)GameObject.Find("information").GetComponent<countries>().algeriaGold,
             TunisAIGold = (int)GameObject.Find("information").GetComponent<countries>().tunisGold,
             SardiniaAIGold = (int)GameObject.Find("information").GetComponent<countries>().sardGold,
             SicilyAIGold = (int)GameObject.Find("information").GetComponent<countries>().sicilyGold,
             NaplesAIGold = (int)GameObject.Find("information").GetComponent<countries>().naplesGold,
             LuccaAIGold = (int)GameObject.Find("information").GetComponent<countries>().luccaGold,
             ItalyAIGold = (int)GameObject.Find("information").GetComponent<countries>().italyGold,
             HelvetiaAIGold = (int)GameObject.Find("information").GetComponent<countries>().helvetiaGold,
             AustriaAIGold = (int)GameObject.Find("information").GetComponent<countries>().austrianGold,
             OttomanAIGold = (int)GameObject.Find("information").GetComponent<countries>().ottomanGold,
             MontenegroAIGold = (int)GameObject.Find("information").GetComponent<countries>().monteGold,
             PrussiaAIGold = (int)GameObject.Find("information").GetComponent<countries>().prussiaGold,
             WarsawAIGold = (int)GameObject.Find("information").GetComponent<countries>().warsawGold,
             RussiaAIGold = (int)GameObject.Find("information").GetComponent<countries>().russianGold,
             SwedenAIGold = (int)GameObject.Find("information").GetComponent<countries>().swedenGold,
             NorwayAIGold = (int)GameObject.Find("information").GetComponent<countries>().norwayGold,
             FranceAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().francePopulation,
             SpainAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().spainPopulation,
             PortugalAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().portugalPopulation,
             UKAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().UKPopulation,
             CRAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().CRPopulation,
             MoroccoAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().moroccoPopulation,
             AlgeriaAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().algeriaPopulation,
             TunisAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().tunisPopulation,
             SardiniaAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().sardPopulation,
             SicilyAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().sicilyPopulation,
             NaplesAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().naplesPopulation,
             LuccaAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().luccaPopulation,
             ItalyAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().italyPopulation,
             HelvetiaAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().helvetiaPopulation,
             AustriaAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().austrianPopulation,
             OttomanAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().ottomanPopulation,
             MontenegroAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().montePopulation,
             PrussiaAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().prussiaPopulation,
             WarsawAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().warsawPopulation,
             RussiaAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().russianPopulation,
             SwedenAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().swedenPopulation,
             NorwayAIPopulation = (int)GameObject.Find("information").GetComponent<countries>().norwayPopulation,
             FranceAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().franceMaterial,
             SpainAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().spainMaterial,
             PortugalAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().portugalMaterial,
             UKAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().UKMaterial,
             CRAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().CRMaterial,
             MoroccoAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().moroccoMaterial,
             AlgeriaAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().algeriaMaterial,
             TunisAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().tunisMaterial,
             SardiniaAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().sardMaterial,
             SicilyAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().sicilyMaterial,
             NaplesAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().naplesMaterial,
             LuccaAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().luccaMaterial,
             ItalyAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().italyMaterial,
             HelvetiaAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().helvetiaMaterial,
             AustriaAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().austrianMaterial,
             OttomanAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().ottomanMaterial,
             MontenegroAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().monteMaterial,
             PrussiaAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().prussiaMaterial,
             WarsawAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().warsawMaterial,
             RussiaAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().russianMaterial,
             SwedenAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().swedenMaterial,
             NorwayAIMaterial = (int)GameObject.Find("information").GetComponent<countries>().norwayMaterial,
 
             FNWcontroller = (int)GameObject.Find("france_nw").GetComponent<Control>().controller,
             FNWCavalry = (int)GameObject.Find("france_nw").GetComponent<Control>().cavalry,
             FNWInfantry = (int)GameObject.Find("france_nw").GetComponent<Control>().infantry,
             FNWArtillery = (int)GameObject.Find("france_nw").GetComponent<Control>().artillery,
             FSEcontroller = (int)GameObject.Find("france_se").GetComponent<Control>().controller,
             FSECavalry = (int)GameObject.Find("france_se").GetComponent<Control>().cavalry,
             FSEInfantry = (int)GameObject.Find("france_se").GetComponent<Control>().infantry,
             FSEArtillery = (int)GameObject.Find("france_se").GetComponent<Control>().artillery,
             FNEcontroller = (int)GameObject.Find("france_ne").GetComponent<Control>().controller,
             FNECavalry = (int)GameObject.Find("france_ne").GetComponent<Control>().cavalry,
             FNEInfantry = (int)GameObject.Find("france_ne").GetComponent<Control>().infantry,
             FNEArtillery = (int)GameObject.Find("france_ne").GetComponent<Control>().artillery,
             FSWcontroller = (int)GameObject.Find("france_sw").GetComponent<Control>().controller,
             FSWCavalry = (int)GameObject.Find("france_sw").GetComponent<Control>().cavalry,
             FSWInfantry = (int)GameObject.Find("france_sw").GetComponent<Control>().infantry,
             FSWArtillery = (int)GameObject.Find("france_sw").GetComponent<Control>().artillery,
 
             SNcontroller = (int)GameObject.Find("spain_n").GetComponent<Control>().controller,
             SNCavalry = (int)GameObject.Find("spain_n").GetComponent<Control>().cavalry,
             SNInfantry = (int)GameObject.Find("spain_n").GetComponent<Control>().infantry,
             SNArtillery = (int)GameObject.Find("spain_n").GetComponent<Control>().artillery,
             SScontroller = (int)GameObject.Find("spain_s").GetComponent<Control>().controller,
             SSCavalry = (int)GameObject.Find("spain_s").GetComponent<Control>().cavalry,
             SSInfantry = (int)GameObject.Find("spain_s").GetComponent<Control>().infantry,
             SSArtillery = (int)GameObject.Find("spain_s").GetComponent<Control>().artillery,
 
             PNcontroller = (int)GameObject.Find("portugal_n").GetComponent<Control>().controller,
             PNCavalry = (int)GameObject.Find("portugal_n").GetComponent<Control>().cavalry,
             PNInfantry = (int)GameObject.Find("portugal_n").GetComponent<Control>().infantry,
             PNArtillery = (int)GameObject.Find("portugal_n").GetComponent<Control>().artillery,
             PScontroller = (int)GameObject.Find("portugal_s").GetComponent<Control>().controller,
             PSCavalry = (int)GameObject.Find("portugal_s").GetComponent<Control>().cavalry,
             PSInfantry = (int)GameObject.Find("portugal_s").GetComponent<Control>().infantry,
             PSArtillery = (int)GameObject.Find("portugal_s").GetComponent<Control>().artillery,
 
             INcontroller = (int)GameObject.Find("ireland_n").GetComponent<Control>().controller,
             INCavalry = (int)GameObject.Find("ireland_n").GetComponent<Control>().cavalry,
             INInfantry = (int)GameObject.Find("ireland_n").GetComponent<Control>().infantry,
             INArtillery = (int)GameObject.Find("ireland_n").GetComponent<Control>().artillery,
             IScontroller = (int)GameObject.Find("ireland_s").GetComponent<Control>().controller,
             ISCavalry = (int)GameObject.Find("ireland_s").GetComponent<Control>().cavalry,
             ISInfantry = (int)GameObject.Find("ireland_s").GetComponent<Control>().infantry,
             ISArtillery = (int)GameObject.Find("ireland_s").GetComponent<Control>().artillery,
             EEcontroller = (int)GameObject.Find("england_e").GetComponent<Control>().controller,
             EECavalry = (int)GameObject.Find("england_e").GetComponent<Control>().cavalry,
             EEInfantry = (int)GameObject.Find("england_e").GetComponent<Control>().infantry,
             EEArtillery = (int)GameObject.Find("england_e").GetComponent<Control>().artillery,
             EWcontroller = (int)GameObject.Find("england_w").GetComponent<Control>().controller,
             EWCavalry = (int)GameObject.Find("england_w").GetComponent<Control>().cavalry,
             EWInfantry = (int)GameObject.Find("england_w").GetComponent<Control>().infantry,
             EWArtillery = (int)GameObject.Find("england_w").GetComponent<Control>().artillery,
             Scontroller = (int)GameObject.Find("scotland").GetComponent<Control>().controller,
             SCavalry = (int)GameObject.Find("scotland").GetComponent<Control>().cavalry,
             SInfantry = (int)GameObject.Find("scotland").GetComponent<Control>().infantry,
             SArtillery = (int)GameObject.Find("scotland").GetComponent<Control>().artillery,
             CNcontroller = (int)GameObject.Find("cr_n").GetComponent<Control>().controller,
             CNCavalry = (int)GameObject.Find("cr_n").GetComponent<Control>().cavalry,
             CNInfantry = (int)GameObject.Find("cr_n").GetComponent<Control>().infantry,
             CNArtillery = (int)GameObject.Find("cr_n").GetComponent<Control>().artillery,
             CScontroller = (int)GameObject.Find("cr_s").GetComponent<Control>().controller,
             CSCavalry = (int)GameObject.Find("cr_s").GetComponent<Control>().cavalry,
             CSInfantry = (int)GameObject.Find("cr_s").GetComponent<Control>().infantry,
             CSArtillery = (int)GameObject.Find("cr_s").GetComponent<Control>().artillery,
             MEcontroller = (int)GameObject.Find("morocco_e").GetComponent<Control>().controller,
             MECavalry = (int)GameObject.Find("morocco_e").GetComponent<Control>().cavalry,
             MEInfantry = (int)GameObject.Find("morocco_e").GetComponent<Control>().infantry,
             MEArtillery = (int)GameObject.Find("morocco_e").GetComponent<Control>().artillery,
             MWcontroller = (int)GameObject.Find("morocco_w").GetComponent<Control>().controller,
             MWCavalry = (int)GameObject.Find("morocco_w").GetComponent<Control>().cavalry,
             MWInfantry = (int)GameObject.Find("morocco_w").GetComponent<Control>().infantry,
             MWArtillery = (int)GameObject.Find("morocco_w").GetComponent<Control>().artillery,
             AEcontroller = (int)GameObject.Find("algeria_e").GetComponent<Control>().controller,
             AECavalry = (int)GameObject.Find("algeria_e").GetComponent<Control>().cavalry,
             AEInfantry = (int)GameObject.Find("algeria_e").GetComponent<Control>().infantry,
             AEArtillery = (int)GameObject.Find("algeria_e").GetComponent<Control>().artillery,
             ACcontroller = (int)GameObject.Find("algeria_c").GetComponent<Control>().controller,
             ACCavalry = (int)GameObject.Find("algeria_c").GetComponent<Control>().cavalry,
             ACInfantry = (int)GameObject.Find("algeria_c").GetComponent<Control>().infantry,
             ACArtillery = (int)GameObject.Find("algeria_c").GetComponent<Control>().artillery,
             AWcontroller = (int)GameObject.Find("algeria_w").GetComponent<Control>().controller,
             AWCavalry = (int)GameObject.Find("algeria_w").GetComponent<Control>().cavalry,
             AWInfantry = (int)GameObject.Find("algeria_w").GetComponent<Control>().infantry,
             AWArtillery = (int)GameObject.Find("algeria_w").GetComponent<Control>().artillery,
             TNcontroller = (int)GameObject.Find("tunis_n").GetComponent<Control>().controller,
             TNCavalry = (int)GameObject.Find("tunis_n").GetComponent<Control>().cavalry,
             TNInfantry = (int)GameObject.Find("tunis_n").GetComponent<Control>().infantry,
             TNArtillery = (int)GameObject.Find("tunis_n").GetComponent<Control>().artillery,
             TScontroller = (int)GameObject.Find("tunis_s").GetComponent<Control>().controller,
             TSCavalry = (int)GameObject.Find("tunis_s").GetComponent<Control>().cavalry,
             TSInfantry = (int)GameObject.Find("tunis_s").GetComponent<Control>().infantry,
             TSArtillery = (int)GameObject.Find("tunis_s").GetComponent<Control>().artillery,
             SACcontroller = (int)GameObject.Find("sardinia_c").GetComponent<Control>().controller,
             SACCavalry = (int)GameObject.Find("sardinia_c").GetComponent<Control>().cavalry,
             SACInfantry = (int)GameObject.Find("sardinia_c").GetComponent<Control>().infantry,
             SACArtillery = (int)GameObject.Find("sardinia_c").GetComponent<Control>().artillery,
             SICcontroller = (int)GameObject.Find("sicily_c").GetComponent<Control>().controller,
             SICCavalry = (int)GameObject.Find("sicily_c").GetComponent<Control>().cavalry,
             SICInfantry = (int)GameObject.Find("sicily_c").GetComponent<Control>().infantry,
             SICArtillery = (int)GameObject.Find("sicily_c").GetComponent<Control>().artillery,
             NEcontroller = (int)GameObject.Find("naples_e").GetComponent<Control>().controller,
             NECavalry = (int)GameObject.Find("naples_e").GetComponent<Control>().cavalry,
             NEInfantry = (int)GameObject.Find("naples_e").GetComponent<Control>().infantry,
             NEArtillery = (int)GameObject.Find("naples_e").GetComponent<Control>().artillery,
             NWcontroller = (int)GameObject.Find("naples_w").GetComponent<Control>().controller,
             NWCavalry = (int)GameObject.Find("naples_w").GetComponent<Control>().cavalry,
             NWInfantry = (int)GameObject.Find("naples_w").GetComponent<Control>().infantry,
             NWArtillery = (int)GameObject.Find("naples_w").GetComponent<Control>().artillery,
             NNcontroller = (int)GameObject.Find("naples_n").GetComponent<Control>().controller,
             NNCavalry = (int)GameObject.Find("naples_n").GetComponent<Control>().cavalry,
             NNInfantry = (int)GameObject.Find("naples_n").GetComponent<Control>().infantry,
             NNArtillery = (int)GameObject.Find("naples_n").GetComponent<Control>().artillery,
         };
     }
 }


I have t$$anonymous$$s error show up every time I try to save"NullReferenceException: Object reference not set to an instance of an object SaveSystem.fromAI (countries countries) (at Assets/Code/SaveSystem.cs:196)" Line 196 is "return new SaveSystem." I'm not sure what I am doing wrong, t$$anonymous$$s is my first time with Binary Writers. Also yes I know there are a lot of data points.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Captain_Pineapple · Oct 20, 2022 at 06:21 AM

For t$$anonymous$$s you will not find an answer here. Apart from Questions regarding NullReferenceException not being allowed t$$anonymous$$s is just not solveable. You have to do t$$anonymous$$s on your own. ANY 1 or more Components or GameObjects are not being found. Good luck figuring out w$$anonymous$$ch.

What is a nullReferenceException and how do i fix it.

Comment
Add comment · Show 4 · 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
avatar image CodeMateo · Oct 20, 2022 at 02:12 PM 0
Share

oh ok, could you tell me how a return new can be null?

avatar image Captain_Pineapple CodeMateo · Oct 20, 2022 at 04:43 PM 0
Share

Hey, please try to post answers as answers and comments as comments.


Example for Unity

   GameObject.Find("morocco_e").GetComponent<Control>().cavalry

throws nullref if - there is no GameObject with name "morocco_e" - there is a Gameobject wit the name but there is no Component Control on the GameObject

avatar image CodeMateo · Oct 20, 2022 at 07:36 PM 0
Share

Sorry I’m really new to this and I’m doing this on my phone and it looks different then on my computer. Thank you, I did find the answer. I put Algeria_c when it should be Algeria_m. I think it’s weird that it put the error down as line 196 return new, and not where the line was actually null at

avatar image Captain_Pineapple CodeMateo · Oct 20, 2022 at 09:41 PM 0
Share

No problem, just try to remember it next time. Also please remember to mark correct answers as such so that others can easier find solutions to their problems.

Regarding the line: It's not weird, it is common, as from C#'s perspective, this is all one line where you create a new object. Which is - to be honest - just one of the points that shows that this current version of your code should be refactored. The longer you work with this, the more errors you will encounter with this. And god have mercy if you ever decide to change some names of any objects.

Something like:

   SICcontroller = (int)GameObject.Find("sicily_c").GetComponent<Control>().controller,
          SICCavalry = (int)GameObject.Find("sicily_c").GetComponent<Control>().cavalry,
          SICInfantry = (int)GameObject.Find("sicily_c").GetComponent<Control>().infantry,
          SICArtillery = (int)GameObject.Find("sicily_c").GetComponent<Control>().artillery,

would be way more performant and easier to maintain if it was:

    var control = GameObject.Find("sicily_c").GetComponent<Control>();
    if(control == null)
           Debug.LogError("OMG sicily has no CONTROL!!!");
    SICcontroller = (int)control.controller;
    SICCavalry = (int)control.cavalry;
    SICInfantry = (int)control.infantry;
    SICArtillery = (int)control.artillery;

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.

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

193 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

Related Questions

IOS File Path for saving data 1 Answer

Creating an instance of a prefab at start? 1 Answer

c# How would I go about doing a High Score Board? 1 Answer

Simple way to save large files 0 Answers

How to SAVE/LOAD Unity Game in Mac/WebGL? 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