Editing Script during runtime

I want to ask if script editing during runtime is officially supported ?

I noticed that for simple scenes/scripts, it works. However, if I use something like a singleton pattern, the classes inside those singleton objects become null whenever I edit my script in runtime.

For reference: http://wiki.unity3d.com/index.php/Singleton

Any ideas ?

This is probably because Unity does not serialize statics, so the singleton instance is returned to null.

I cannot help with editing scripts at runtime, though. What are you trying to do?

Editing scripts while playing is very error prone and I wouldn’t recommend it at all.

I am writing some AI code for NPCs, and I’d like to change its behavior directly during playing.
Any recommendation how to do this ?

Build a simple state machine. You can for example do this by having a base class for your AI states, and in this state class u define some virtual methods and then override them in inherited states. By doing this you can call different methods from the same identifier. Then add your states to some container (ex System.Collections.Generic.List) and execute them.

This is just a method for abstraction and It’s up to you how much of the AI behaviour you want to abstract out from the AI class.

Polymorphism
State Machines

I know about state machines, but it’s just an AI algorithm.
My question is about how I can make Unity to allow me to edit the scripts during play and see my changes in real time.

For example, if I change my state machine in a script, I want it to be reflected directly in the game.