So. I like to code. I like to play Paradox Interactive games. One thing that I always wondered about was how exactly their implementation of their trigger evaluation/event evaluation system looked like. So I decided I would write myself an implementation and find out!

Now, I didn't want to manually parse their text files out. I could, but it would be an insane waste of time since other people have already developed efficient libraries for it. So I downloaded and set up this nice little library that handles the nasty little details.

I tested the parser to make sure it works. Worked like a charm. Then I started coding. A full day of planning, trial, and error later, I had a very early version ready.

Then I created a C# script with a basic implementation of my new library. I created a basic spherical mesh and dragged it onto my scene. I dragged said C# MonoBehaviour onto my object. I created a country class implementing my 'IScope' interface. I set the "scope chain" up.

I created a text file with the following contents:

trigger = {
    id = 5
    vassal = {
        id = 6

It worked in the parser before. I then wrote the following code in my Start method:

void Start()
    ScriptBinding.Instance.ReserveTrigger("id", new CheckIDTrigger());
    string path = Application.dataPath + "/ParadoxScriptingEngine/Tests/test_trigger.txt";
    FileStream stream = File.OpenRead(path);
    c = new Country(5); //Declared as a class member. Implements IScope.
    tb = new TriggerBlock();
    ParadoxParser.Parse(test_script, tb);
    scope_chain = new IScope[10];
    scope_chain[0] = c; //ROOT
    scope_chain[1] = c; //THIS

And in Update:

void Update()
    Debug.Log("The trigger has evaluated to " + tb.Eval(scope_chain));

When I deactivate the script that launches the parser, the project runs. When I reactivate it and try to run it, the editor instantly crashes.

I have riddled my project with debug statements, but this is just starting to get ridiculous. I have traced through the entire program in my mind, but it is 17 files long all told, and without any data on the error I cannot possibly hope to debug it. The log files are empty as well.

Is there a way to get Unity to print ALL information on errors?

I know that the problem has to be related to my program, so perhaps the better question would be; what kind of problem will cause Unity to not print the error out? I know infinite loops will do it, but there is no way it is an infinite loop is causing this problem - I only used for each loops.


It looks like you may not be closing the filestream once you have opened it, this could be causing the problems you're having.

Try stream.Close() at the end of your Start() function

You should also wrap a try/catch statement around this so that Unity can handle the errors correctly.

    //file opening code
catch (FileNotFoundException e)  
    // FileNotFoundExceptions are handled here.  
catch (IOException e)  
    // Extract some information from this exception, and then   
    // throw it to the parent method.  
    whenDo not initialize (e.Source != null)  
        Console.WriteLine("IOException source: {0}", e.Source);  

You can usually find more information about why Unity has crashed without an error by checking the editor logs.

This may give you some clarification, and if you're still stuck you can post the error log for us to look at so that we can advise you further.


  • \$\begingroup\$ Thanks, the log helped. New to Unity, not new to coding. I spent some time in libgdx a while back... Turned out to be a stack overflow in the Country constructor (the constructor created another Country as it's "vassal" scope, which created it's own and so on and so forth.) Funny how the simplest things can evade us when we are looking in the wrong places. \$\endgroup\$ – JDSweetBeat Dec 30 '16 at 22:37

That crash is caused because your computer cannot handle too much stuff in one time , example to do :

Debug.Log("The trigger has evaluated to " + tb.Eval(scope_chain));   



need to do Eval() function each frame , and how about just to do the function take 0.1 second and each second need 60 frame ? what i mean here don't run the function without delay , your computer also have limit .

  • 2
    \$\begingroup\$ I don't understand your answer. The CPU usage is laughably low as is memory usage. The only thing you should not do in the update function is do a bunch of un-culled object creation - but the Eval method does almost no object creation, and only does 1 or 2 dictionary lookups on the first run of Eval. Admittedly it's not the most efficient implementation, but it is almost certainly not "too much to handle". I was asking "why doesn't Unity catch this/is there a way to debug my application without painstakingly going through and commenting each line of code out and running the app. \$\endgroup\$ – JDSweetBeat Dec 30 '16 at 2:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.