What’s differences between construction script and event graph?
Construction Script is a function, Event Graph is not.
and ? Then why event graph stays there ?
Construction Script happens before the blueprint is spawned, so say you wanted weapons attached to a character through sockets before it spawned you would do it there.
The major difference is that the construction script is executed during world editing. They are most powerful when used in objects that are placed in the level editor so you can create smart objects that automate all sorts of things during editing. They are also executed in the blueprint editor: the actor you see in the BP editor viewport is the result of the construction script. So, for example, if you use some kind of modular NPC character with randomized body proportions and clothing, if you do it in the constructor script you can preview the results right in the BP editor viewport instead of having to press “play”.
Construction occurs upon instantiation. Instantiating an object does not mean it is spawned in the game, and does not mean that any event has occurred. Despite the fact that they appear coupled due to the functions exposed to blueprints, they’re 100% different and programmatically occur at very different times.
In any object oriented programming paradigm (language agnostic), instantiating an object is simply creating the object from its class. This is the soonest you can possibly run any logic, as it occurs right when it is created (instantiated) in memory. This also means literally nothing else has taken place within this class/object, save the parent’s construction if you call it prior to your child’s construction logic. Construct(ion) logic means: This runs the moment we create (instantiate) this object, before it is placed in the world or anything else has occurred.
The event graph is exactly as it sounds: a collection of events which this object has subscribed to. OnBeginPlay, for example, simply means this object is firing logic based on the event that it has begun play in the world.
In a blueprint example of spawning an actor by class, it can appear a bit conflated because two things are happening. First, the object is instantiated and the construction script fires. Second, the object (actor) is placed in the world. By being in the world, it receives events as they occur.
The reason construction fires in the editor is because of the above. It is instantiated, therefor it runs its construction script. The reason the event graph does not, is because the game is not running, therefore it is not triggering any events.