scripting_continued.rst 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. .. _doc_scripting_continued:
  2. Scripting (continued)
  3. =====================
  4. Notifications
  5. -------------
  6. Godot has a low-level notifications system. You don't are usually not needed for
  7. scripting, as it's too low-level and virtual functions are provided for
  8. most of them. You can learn more about how notifications work under the hood in :ref:`doc_godot_notifications`.
  9. .. tabs::
  10. .. code-tab:: gdscript GDScript
  11. func _notification(what):
  12. match what:
  13. NOTIFICATION_READY:
  14. print("This is the same as overriding _ready()...")
  15. NOTIFICATION_PROCESS:
  16. print("This is the same as overriding _process()...")
  17. .. code-tab:: csharp
  18. public override void _Notification(int what)
  19. {
  20. base._Notification(what);
  21. switch (what)
  22. {
  23. case NotificationReady:
  24. GD.Print("This is the same as overriding _Ready()...");
  25. break;
  26. case NotificationProcess:
  27. var delta = GetProcessDeltaTime();
  28. GD.Print("This is the same as overriding _Process()...");
  29. break;
  30. }
  31. }
  32. The documentation of each class in the :ref:`Class Reference <toc-class-ref>`
  33. shows the notifications it can receive. However, in most cases GDScript
  34. provides simpler overridable functions.
  35. Overridable functions
  36. ---------------------
  37. Such overridable functions, which are described as
  38. follows, can be applied to nodes:
  39. .. tabs::
  40. .. code-tab:: gdscript GDScript
  41. func _enter_tree():
  42. # When the node enters the Scene Tree, it becomes active
  43. # and this function is called. Children nodes have not entered
  44. # the active scene yet. In general, it's better to use _ready()
  45. # for most cases.
  46. pass
  47. func _ready():
  48. # This function is called after _enter_tree, but it ensures
  49. # that all children nodes have also entered the Scene Tree,
  50. # and became active.
  51. pass
  52. func _exit_tree():
  53. # When the node exits the Scene Tree, this function is called.
  54. # Children nodes have all exited the Scene Tree at this point
  55. # and all became inactive.
  56. pass
  57. func _process(delta):
  58. # This function is called every frame.
  59. pass
  60. func _physics_process(delta):
  61. # This is called every physics frame.
  62. pass
  63. .. code-tab:: csharp
  64. public override void _EnterTree()
  65. {
  66. // When the node enters the Scene Tree, it becomes active
  67. // and this function is called. Children nodes have not entered
  68. // the active scene yet. In general, it's better to use _ready()
  69. // for most cases.
  70. base._EnterTree();
  71. }
  72. public override void _Ready()
  73. {
  74. // This function is called after _enter_tree, but it ensures
  75. // that all children nodes have also entered the Scene Tree,
  76. // and became active.
  77. base._Ready();
  78. }
  79. public override void _ExitTree()
  80. {
  81. // When the node exits the Scene Tree, this function is called.
  82. // Children nodes have all exited the Scene Tree at this point
  83. // and all became inactive.
  84. base._ExitTree();
  85. }
  86. public override void _Process(float delta)
  87. {
  88. // This function is called every frame.
  89. base._Process(delta);
  90. }
  91. public override void _PhysicsProcess(float delta)
  92. {
  93. // This is called every physics frame.
  94. base._PhysicsProcess(delta);
  95. }