Forum begins after the advertisement:
[Part 14] Damage Floating Text blocking clicks in Screen Space – Camera
Home › Forums › Video Game Tutorial Series › Creating a Rogue-like Shoot-em Up in Unity › [Part 14] Damage Floating Text blocking clicks in Screen Space – Camera
- This topic has 5 replies, 3 voices, and was last updated 1 week ago by
Terence.
-
AuthorPosts
-
August 18, 2025 at 6:32 am #18668::
Hey guys, I used the “Screen Space – Camera” as intended, but oddly it makes the “OPEN” button unclickable. If I use “Screen Space – Overlay” I can click the button, but of course some Effects won’t show up. What causes the unclickable button?
August 18, 2025 at 6:40 am #18669::It sounds like you’re encountering an issue with the UI setup in Unity when using the “Screen Space – Camera” canvas mode. Here are a few potential reasons why the button might be unclickable:
-
Event System: Ensure that you have an Event System in your scene. Without it, UI elements won’t be able to receive input events.
-
Canvas Camera: Make sure that the Camera assigned to your Canvas is set up correctly. The camera should be positioned in a way that it can render the UI elements. If the camera is not in the correct position, the UI might not be visible or clickable.
-
Sorting Layers: Check the sorting layers and order of the UI elements. If there are other UI elements or components that are rendered on top of the button, they may be blocking the interaction.
-
Graphic Raycaster: Ensure that the Canvas has a Graphic Raycaster component attached. This component is necessary for the UI elements to receive input events.
-
Button and Parent Objects: Check if the button or any parent objects are set to inactive or have their interactable properties set to false. Also, ensure that there are no transparent images or panels overlaying the button.
-
RectTransform: Verify that the RectTransform of the button is correctly sized and positioned within the canvas. If it’s outside the bounds of the canvas or off-screen, it won’t be clickable.
-
Z-Index: For “Screen Space – Camera,” the Z position of the UI elements matters. Make sure your button is at a proper Z value relative to the camera to ensure it’s rendered properly.
If you check all of these considerations and the button is still unclickable, try creating a simple test button in a new scene with a basic setup to see if the issue persists. This can help isolate whether it’s a scene-specific problem or a broader issue with your setup.
August 18, 2025 at 12:08 pm #18670::My guess is that another Canvas, Canvas element or sprite is blocking your button in Screen Space – Camera mode. You can view your Scene in 3D mode (unclick the 2D button on the Unity UI) to get a better view of whether something is behind your Screen Space – Camera UI. That will likely be the object that is blocking your button.
Sharing this short here we made awhile ago as well, as the second half may be relevant to your situation.
August 19, 2025 at 1:55 am #18694August 19, 2025 at 3:30 am #18696::Hi Terence, I found out the problem is with the “Damage Text Canvas”. If I disable it in the canvas, everything works fine. Were there any other adjustments made that haven’t been documented yet?
August 19, 2025 at 3:35 am #18697::It sounds like the “Damage Text Canvas” might be interfering with the button interactions in your UI. Here are a few things to consider regarding adjustments and fixes:
-
Raycasting: Ensure that the “Damage Text Canvas” has a Graphic Raycaster component. If it does, and it’s set to block raycasts, it might be preventing interaction with buttons behind it. You can adjust its Raycast Target property on any UI elements in that canvas.
-
Sorting Order: Check the sorting order of the “Damage Text Canvas.” If it’s higher than the main UI canvas, it could be rendering on top of your buttons, making them unclickable.
-
Canvas Group: If you’re using a Canvas Group component on the “Damage Text Canvas,” verify that its “Interactable” and “Blocks Raycasts” properties are set correctly. If the canvas group is set to not interactable, it will block interactions with underlying canvases.
-
Canvas Render Mode: If the “Damage Text Canvas” is set to “Screen Space – Camera,” verify that the camera settings are correct and that the canvas is positioned properly within the camera’s view.
-
Layering: Use layers to control which UI elements interact with raycasts. If the “Damage Text Canvas” is set to a layer that blocks interaction with other UI elements, that could cause the issue.
-
Debugging: You can temporarily change the alpha (transparency) of the “Damage Text Canvas” to see if it’s visually blocking the button. If that resolves the issue, it’s likely a layering or raycasting problem.
-
Hierarchy Order: Ensure that the hierarchy order of the canvases is correct. Sometimes, simply changing the order in the hierarchy can resolve rendering issues.
If none of these solutions work, you might want to document any specific adjustments you made to the “Damage Text Canvas” and test whether disabling or modifying certain components resolves the issue. This way, you can isolate what might be causing the interference.
August 19, 2025 at 6:36 pm #18717::I fixed the problem by implementing a function to deactivate the canvas while the treasure chest is active. If you have the same problem, just add the code below to the “UITreasureChest.cs” and define the Main Canvas (or the Damage Text Canvas) in the inspector and it will work just fine!
[Header("canvas")] public GameObject canvas; ... private void OnEnable() { canvas.SetActive(false); } ... public void CloseUI() { canvas.SetActive(true); ...
has upvoted this post. August 21, 2025 at 4:43 pm #18748::Another solution to this is to add an extra line to disable Raycast Target on your damage text. This will stop the damage text from blocking clicks.
IEnumerator GenerateFloatingTextCoroutine(string text, Transform target, float duration = 1f, float speed = 50f) { // Start generating the floating text. GameObject textObj = new GameObject("Damage Floating Text"); RectTransform rect = textObj.AddComponent<RectTransform>(); TextMeshProUGUI tmPro = textObj.AddComponent<TextMeshProUGUI>(); tmPro.text = text; tmPro.horizontalAlignment = HorizontalAlignmentOptions.Center; tmPro.verticalAlignment = VerticalAlignmentOptions.Middle; tmPro.fontSize = textFontSize; tmPro.raycastTarget = false; if (textFont) tmPro.font = textFont; rect.position = referenceCamera.WorldToScreenPoint(target.position); // Makes sure this is destroyed after the duration finishes. Destroy(textObj, duration); // Parent the generated text object to the canvas. textObj.transform.SetParent(instance.damageTextCanvas.transform); textObj.transform.SetSiblingIndex(0); // Pan the text upwards and fade it away over time. WaitForEndOfFrame w = new WaitForEndOfFrame(); float t = 0; float yOffset = 0; Vector3 lastKnownPosition = target.position; while (t < duration) { // If the RectTransform is missing for whatever reason, end this loop. if (!rect) break; // Fade the text to the right alpha value. tmPro.color = new Color(tmPro.color.r, tmPro.color.g, tmPro.color.b, 1 - t / duration); // Update the enemy's position if it is still around. if (target) lastKnownPosition = target.position; // Pan the text upwards. yOffset += speed * Time.deltaTime; rect.position = referenceCamera.WorldToScreenPoint(lastKnownPosition + new Vector3(0, yOffset)); // Wait for a frame and update the time. yield return w; t += Time.deltaTime; } }
- 2 anonymous people
-
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: