Skip to content

Commit 4aa765a

Browse files
committed
Update docs about objects lifetime
FlaxEngine/FlaxEngine#2756
1 parent eb5b753 commit 4aa765a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

manual/scripting/objects-lifetime.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public override void OnStart()
1414
var light = new PointLight();
1515
light.Color = Color.Blue;
1616
light.Parent = Actor;
17+
// object will be part of the scene hierarhcy
18+
// engine will destroy it on scene unload
1719
}
1820
```
1921
# [C++](#tab/code-cpp)
@@ -23,6 +25,8 @@ void ExampleScript::OnStart()
2325
auto light = New<PointLight>();
2426
light->Color = Color::Blue;
2527
light->SetParent(GetActor());
28+
// object will be part of the scene hierarhcy
29+
// engine will destroy it on scene unload
2630
}
2731
```
2832
***
@@ -44,12 +48,14 @@ void ExampleScript::OnStart()
4448
auto script = New<Player>();
4549
script->SetParent(GetActor());
4650
script->HP = 100;
51+
// object will be part of the scene hierarhcy
52+
// engine will destroy it on scene unload
4753
}
4854
```
4955
***
5056

5157
> [!Note]
52-
> Scene objects (actors, scripts) should **not use constructors** to prevent issues.
58+
> Scene objects (actors, scripts) should **not use constructors** other than initialize itself (defaults).
5359
5460
## Removing objects
5561

@@ -80,3 +86,17 @@ Destroy(Actor.GetScript<Player>());
8086
GetActor()->GetScript<ExampleScript>()->DeleteObject();
8187
```
8288
***
89+
90+
## Language-specific
91+
92+
### C#
93+
94+
Various components and APIs that are specific to C# language use `Dispose()` pattern and implement `IDisposable` interface for convenience. For example:
95+
* `Control` - GUI controls use `Dispose` method to destroy UI element,
96+
* `InputAxis`/`InputEvent` - virtual input reading utility has to be released via `Dispose`,
97+
98+
### C++
99+
100+
* Use utility macros: `SAFE_DISPOSE`, `SAFE_RELEASE`, `SAFE_DELETE` to cleanup objects, depending on the method to call.
101+
* Graphics objects such as `GPUTexture` or `GPUBuffer` can be cleared via `SAFE_DELETE_GPU_RESOURCE` macro. Those are normal scripting objects but invoking `ReleaseGPU` beforehand helps to reduce memory pressure when unused.
102+
* `Task` system uses automatic auto-destruction of past tasks. There is no need to manually destroy objects after use.

0 commit comments

Comments
 (0)