diff --git a/Source/Engine/UI/GUI/Common/RenderToTextureControl.cs b/Source/Engine/UI/GUI/Common/RenderToTextureControl.cs
index f1a9c69a5..abaf69e21 100644
--- a/Source/Engine/UI/GUI/Common/RenderToTextureControl.cs
+++ b/Source/Engine/UI/GUI/Common/RenderToTextureControl.cs
@@ -9,7 +9,7 @@ namespace FlaxEngine.GUI
public class RenderToTextureControl : ContainerControl
{
private bool _invalid, _redrawRegistered, _isDuringTextureDraw;
- private bool _autoSize = true;
+ private bool _autoSize = true, _constantInvalidate = false;
private GPUTexture _texture;
private Float2 _textureSize;
private MaterialBase _drawMaterial;
@@ -60,6 +60,33 @@ namespace FlaxEngine.GUI
[EditorOrder(30)]
public bool AutomaticInvalidate { get; set; } = true;
+ ///
+ /// Gets or sets the value whether cached texture data should be invalidated every frame (eg. when UI is animated).
+ ///
+ [EditorOrder(40)]
+ public bool ConstantInvalidate
+ {
+ get => _constantInvalidate;
+ set
+ {
+ if (_constantInvalidate != value)
+ {
+ _constantInvalidate = value;
+ if (value)
+ {
+ // Register for constant invalidation
+ Invalidate();
+ }
+ else if (_invalid && _redrawRegistered)
+ {
+ // Don't invalidate anymore
+ _redrawRegistered = false;
+ Scripting.Draw -= OnDraw;
+ }
+ }
+ }
+ }
+
///
/// Gets or sets the GUI material used to draw the cached texture to the screen.
/// Can be used to post-process underlying GUI with a custom shader (eg. chromatic-aberration, blur or tint). If not set, simple texture copy is performed.
@@ -116,13 +143,16 @@ namespace FlaxEngine.GUI
private void OnDraw()
{
- if (_redrawRegistered)
+ if (!ConstantInvalidate)
{
- _redrawRegistered = false;
- Scripting.Draw -= OnDraw;
+ if (_redrawRegistered)
+ {
+ _redrawRegistered = false;
+ Scripting.Draw -= OnDraw;
+ }
+ if (!_invalid)
+ return;
}
- if (!_invalid)
- return;
_invalid = false;
if (!_texture)