playMaker

Author Topic: NullReferenceException[SOLVED]  (Read 137 times)

blackant

  • Sr. Member
  • ****
  • Posts: 366
  • http://blackantmaster.com
    • View Profile
    • blackantmaster.com
NullReferenceException[SOLVED]
« on: August 09, 2018, 11:10:17 AM »
Hello,

I'm trying to create an action that check if a file exist and send EVent from the result.

the thing is that if the file doesn't exist, i don't get any problem and the event is called correctly.

but after that, once the file exists, it can't go further because i miss something, resulting of the error message


Code: [Select]
NullReferenceException: Object reference not set to an instance of an object
TileWorld.TileWorldCreatorSaveLoad.Load (System.String _path, TileWorld.TileWorldCreator _creator) (at Assets/TileWorldCreator/_Core/Utility/TileWorldCreatorSaveLoad.cs:125)
HutongGames.PlayMaker.Actions.TileWorldLoadMap.OnEnter () (at Assets/PlayMaker/Actions/TileWorldCreation/TileWorldLoadMap.cs:32)
HutongGames.PlayMaker.FsmState.ActivateActions (Int32 startIndex) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:205)
HutongGames.PlayMaker.FsmState.OnEnter () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:175)
HutongGames.PlayMaker.Fsm.EnterState (HutongGames.PlayMaker.FsmState state) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2767)
HutongGames.PlayMaker.Fsm.SwitchState (HutongGames.PlayMaker.FsmState toState) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2714)
HutongGames.PlayMaker.Fsm.UpdateStateChanges () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2642)
HutongGames.PlayMaker.Fsm.Start () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:1925)
PlayMakerFSM.Start () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/PlayMakerFSM.cs:548)

here is my code
Code: [Select]
public override void OnEnter()
{
var Path = "Assets/Ressources/Saves/"+ MapName.Value +".xml";
var _File = File.Exists(Path);


if(_File)
{
TileWorldCreatorSaveLoad.Load(Path,creator);
creator.GetMapSeed();
Fsm.Event(ifFileFund);
}

Fsm.Event(IfNoFile);


}
« Last Edit: August 09, 2018, 11:48:55 PM by blackant »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3523
    • View Profile
    • jinxtergames
Re: NullReferenceException
« Reply #1 on: August 09, 2018, 08:47:02 PM »
Hi.
Maybe the 'TileWorldCreatorSaveLoad.Load' needs the complete path.
For example (D:/UnityProject/2018/Assets/Ressources/Saves/"+ MapName.Value +".xml)

Offtopic :
Why don't you use File.Exists(Path) inside the if statement instead of using an extra bool for this.

blackant

  • Sr. Member
  • ****
  • Posts: 366
  • http://blackantmaster.com
    • View Profile
    • blackantmaster.com
Re: NullReferenceException
« Reply #2 on: August 09, 2018, 11:29:17 PM »
thanks i removed the bool, i think i was tireed... :)

i tryed to set full path, but it coesn't help cause it return something more

Code: [Select]
DirectoryNotFoundException: Could not find a part of the path "F:\Projets\Unity\KetchUp MayO\Assets\Resources\Savess\Level 1.xml".
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/FileStream.cs:292)
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean isAsync, Boolean anonymous)
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access)
(wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess)
TileWorld.TileWorldCreatorSaveLoad.Load (System.String _path, TileWorld.TileWorldCreator _creator) (at Assets/TileWorldCreator/_Core/Utility/TileWorldCreatorSaveLoad.cs:114)
HutongGames.PlayMaker.Actions.TileWorldLoadMap.OnEnter () (at Assets/PlayMaker/Actions/TileWorldCreation/TileWorldLoadMap.cs:31)
HutongGames.PlayMaker.FsmState.ActivateActions (Int32 startIndex) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:205)
HutongGames.PlayMaker.FsmState.OnEnter () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:175)
HutongGames.PlayMaker.Fsm.EnterState (HutongGames.PlayMaker.FsmState state) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2767)
HutongGames.PlayMaker.Fsm.SwitchState (HutongGames.PlayMaker.FsmState toState) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2714)
HutongGames.PlayMaker.Fsm.UpdateStateChanges () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2642)
HutongGames.PlayMaker.Fsm.Start () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:1925)
PlayMakerFSM.Start () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/PlayMakerFSM.cs:548)

blackant

  • Sr. Member
  • ****
  • Posts: 366
  • http://blackantmaster.com
    • View Profile
    • blackantmaster.com
Re: NullReferenceException
« Reply #3 on: August 09, 2018, 11:48:41 PM »
I fund, i did a misstake because i was trying to assign the loading to the creator which i setup after and cause this issue, the thing was to set this creator before.
 ;D