Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Gizmoi · Sep 02, 2014 at 02:09 PM · uibuttonrendererinvisible

uGUI Button without renderer

I need to have a uGUI (new UI) Button that functions without an image, or text, or any kind of visible object on it.

Currently, I can only get a button to work if it has an image or text attached or as a child. Has anyone managed to get this to work, or know if it's even supported?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image senc01a · Sep 02, 2014 at 02:36 PM 0
Share

There is something I don't understand. If the button has no view or visual representation, how are you even supposed to interact with it? I suppose it can work as long as you have the collider, but I think it somehow misses the point. Doesn't it?

avatar image Gizmoi · Sep 02, 2014 at 02:43 PM 0
Share

The button will be represented by other (separate images). And in some cases the button will be invisible. The player will simply tap anywhere on the screen, or swipe anywhere on the screen.

Previously I achieved all of this with my own button system, that did work off simple colliders and thus didn't need an image. But uGUI buttons don't use colliders.

avatar image senc01a · Sep 02, 2014 at 03:30 PM 0
Share

Could you sketch the idea out? Just a simple quickly made sketch to give a feeling of what you are trying to do. Honestly I'm having a hard time imagining it, therefore I can't really help you.

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by AyAMrau · Sep 02, 2014 at 02:49 PM

In the Image component of the object with the Button script, modify the Color field so that the Alpha is 0. This will make the image transparent, but the area occupied by it will still read input.

You could also make a panel with transparent image and use TriggerEvents if you want to read events beyond just button click.

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Gizmoi · Sep 02, 2014 at 02:57 PM 0
Share

This is the workaround I arrived at. But I'd rather not have to have an extra thing rendered if I don't need it.

It would soon become wasteful to have extra invisible textures.

avatar image AyAMrau · Sep 02, 2014 at 03:32 PM 0
Share

It's not the prettiest solution, but after trying out different things it seems unless you have something that would actually render, the events pass right through the area.

avatar image Gizmoi · Sep 15, 2014 at 12:40 PM 0
Share

This is the best solution I've been able to find.

avatar image Jinja · Jul 28, 2015 at 09:27 PM 0
Share

Did anyone find an alternative to this hack solution? I notice that there is an extra drawcall occurring when rendering a blank texture (toggling the Image enabled checkbox reduces the drawcalls by 1)

avatar image jeremyplayraven · Sep 01, 2016 at 07:14 AM 0
Share

On mobile this is an awful solution. It causes overdraw and other performance issues.

avatar image LK84 jeremyplayraven · Sep 01, 2016 at 08:35 AM 0
Share

Have a look here: http://answers.unity3d.com/questions/801928/46-ui-making-a-button-transparent.html

works perfect

avatar image jeremyplayraven LK84 · Sep 01, 2016 at 08:45 AM 0
Share

That also seems a bit hacky. This solution works best for me: http://answers.unity3d.com/questions/844524/ugui-how-to-increase-hitzone-click-area-button-rec.html

The API seems to change with every version of Unity, so check your log for obsolete warnings or check the Unity docs (http://docs.unity3d.com/ScriptReference/UI.Graphic.html) for your version of Unity to see which function you should use:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Hitbox : Graphic
 {
     protected override void OnFillVBO( List<UIVertex> vbo )
     {
         vbo.Clear();
     }
 
     protected override void OnPopulate$$anonymous$$esh( $$anonymous$$esh m )
     {
         m.Clear( false );
     }
 
     // Unity >= 5.5 ?
     protected override void OnPopulate$$anonymous$$esh( VertexHelper vh )
     {
         vh.Clear();
     }
 }
avatar image
0

Answer by chmodseven · Apr 26, 2015 at 07:10 PM

I'm not sure what the OP's intended goal was, but for me the challenge was that I wanted my button to provide a more generous clickable "hot zone" around the visible sprites layered on it, and without adding to draw calls. First I found that the Color alpha technique above does work, but at the expense of a draw call, since the renderer still treats each invisible Image as an object to draw.

So I used the invisible texture approach also mentioned above (just a small blank texture 32*32 I created in Gimp that was entirely just an alpha channel) to use as my button's Source Image. And by saving it in the same ARGB format as my other sprites, I was then able to pack it into the same atlas as my other UI objects using Sprite Packer, and so achieved my invisible hot zone and did not accrue an extra draw call.

As mentioned, it's not the prettiest solution, but at least there doesn't need to be draw call wastage if you pack the blank texture.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by WickedCube · Dec 05, 2017 at 05:57 AM

An empty text with a raycast target is a better workaround as it does not contribute to overdraw.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

29 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Renderer on object disabled after level reload 1 Answer

How do I set up an invisible Button? 1 Answer

uGUI Button size based on text size 1 Answer

GameObject invisible at certain camera angles 0 Answers

Subtracting random numbers instead of 1 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges