Godot Version
v4.4.1.stable.mono.official [49a5bc7b6]
Question
I’m sure the answer is quite simple and it’s staring me in the face, but I just can’t see it.
I made a system that will focus on an item with the camera, and I want to make it so the item it focuses on should also get full priority in terms of rendering. This means drawing on top of EVERYTHING else, no matter what.
I thought this would be easy, but using Top level isn’t an option, as it moves the node to the middle of the current scene, modifying it’s position, which is obviously not ideal, and besides, it’s still not drawing over the blur.
Changin it’s VisiblityLayer seems to do absolutely nothing.
Changing the Z Index to a massive amount isn’t working either, as it still ignores the shader I have, which blurs the screen, and it’s in a CanvasLayer, with a Layer of 95. (I set Z index to 1000 when trying to draw this node on top)
Is there a simple way I can do this, which is also easy to reset once the focus period expired?
Here’s the current “solution” I have, but it’s more of a hack, and I really don’t like it, as it involves duplicating the node and placing it on another CanvasLayer:
private void ExcludeItemFromBlurEffect(Node2D nodeToExclude)
{
CanvasLayer canvasLayer = new();
canvasLayer.Layer = 1000;
Node2D duplicateNode = nodeToExclude.Duplicate() as Node2D;
nodeToExclude.AddChild(canvasLayer);
canvasLayer.AddChild(duplicateNode);
_nodeWeAreExcluding = nodeToExclude;
_duplicatedNode = duplicateNode;
_keepDuplicateOnScreen = true;
}
private void ResetBlurExclusion(Node2D nodeToReset)
{
Array<Node> children = nodeToReset.GetChildren();
if (children.Count == 0)
{
return;
}
_keepDuplicateOnScreen = false;
_nodeWeAreExcluding = null;
_duplicatedNode = null;
foreach (Node child in children)
{
if (child is CanvasLayer canvasLayer)
{
canvasLayer.QueueFree();
}
}
}
Then in process, I just call this function during the focus:
private void ScaleAndKeepItemFocusedWithBlur()
{
_duplicatedNode.Position = NodeHelpers.WorldToViewport(_nodeWeAreExcluding);
_duplicatedNode.Scale = Zoom;
}
Surely there’s a better way?