1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. We want to know how you learned Unity! Help us by taking this quick survey and have a chance at a $25 gift card
    Dismiss Notice
  5. Are you an artist or level designer going to Unite Europe? Join our roundtables there to discuss artist features.
    Dismiss Notice
  6. Unity 5.6 is now released.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice

Alpha Raycaster

Discussion in 'Assets and Asset Store' started by Elringus, Feb 11, 2015.

  1. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    Alpha Raycaster is an editor extension for the Unity UI (uGUI), which enables a precise interaction with a non-rect UI objects.



    The plugin checks for the texture transparency, before deciding whether to allow input events for the target object, which allows a precise interaction with objects that have a non-rect shapes (like round buttons, circles, triangles, map regions etc).

    Links:

    If you have any questions or need support, feel free to post in this thread — I will be happy to assist.
     
    Last edited: Oct 4, 2016
  2. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    In case someone having trouble using the plugin with the sprite atlases: PM me here (or by e-mail) with the invoice number and I will send you new version, which supports both Unity atlasing system (sprite packer) and multiple sprite mode.

    New version with sprite atlasing support, new custom editor and performance improvements is currently pending review in the store (should be out in about 5 days). Be aware, that the price will go up ;)
     
  3. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    Version 1.3 is now live on the Asset Store!

    Main changes:
    • Sprite packing and multiple sprite mode support — alpha check UI objects which uses sprite atlases as their texture
    • New custom editor for the AlphaCheck component — easy one-click setup and auto check for texture configuration
    • Performance optimization and code refactoring
     
  4. junglemason

    junglemason

    Joined:
    Dec 30, 2010
    Posts:
    55
    Looks great!

    Does it still work if the rect of one button overlaps the hit area of another button?

    Example:

    button_overlap.png
     
  5. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    Thank you! Yes, it will work in case of overlapping. You may check this demo for example: http://elringus.me/static/alpha-raycaster/demo.html
    There are kind of map buttons, which rects are overlapping, but they are interacting with input correctly.
     
    Last edited: Jan 15, 2016
    junglemason likes this.
  6. Monticello

    Monticello

    Joined:
    Mar 14, 2015
    Posts:
    1
    Hi,
    Is it possible to define the points/shape of the hit area in one image?
    For example, if I want to map the actual world map into selectable countries, how to do it?
     
  7. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    The “interactable” regions of the texture are defined through the opacity, and the difference might be very small. For example, you may make the overall texture of ~0.99 opacity and mask special regions, which should be interactable with 1.0 opacity. The user will see no difference, but the plugin with alpha threshold set to 1.0 will interact only with masked areas.

    As with the map case: if you want each country to be separate button with its own logic, you will have to create textures with the country boundaries and place them above the actual map. I’ve done something like this in the demo here: https://guiblendmodes.appspot.com/AlphaRaycaster/DemoWebPlayer/DemoWebPlayer.html
    There are 3 “territory boundaries” buttons, which placed upon the map image.
     
    Monticello likes this.
  8. akhil96

    akhil96

    Joined:
    Oct 12, 2014
    Posts:
    35
    is the plugin only supported for orthographic camera?
     
  9. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    Yes, for now it’s only working with an orthographic GUI camera, though I’m planning to add support for the perspective mode in the next update.
     
  10. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    I’ve just submitted version 1.4 with support for perspective camera mode to the asset store.

    It should be live in about 5 days, but if someone wants to get it right now — you may PM me here or by email (don’t forget to include your invoice number) and I will send you the package.
     
    Last edited: Apr 4, 2015
    akhil96 likes this.
  11. akhil96

    akhil96

    Joined:
    Oct 12, 2014
    Posts:
    35
    will it work even if we keep the color alpha value of the image set to zero?,but the touch should be recognised only at the opaque part of image.
     
  12. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    You mean, you want to use a texture with some opaque area, but set the tint color of the Image component with that texture to be fully transparent? In that case, if you disable the “include material alpha” option in the AlphaCheck component — input will still be recognized on the opaque areas of the texture (though, for the user image will be completely invisible). And if the option will be enabled — input won’t be recognized.
     
  13. akhil96

    akhil96

    Joined:
    Oct 12, 2014
    Posts:
    35
    ok fine its a good feature.
    thanks.

    but 50%off is not a big deal as compared to yesterday deal of 90% off for such a great asset(icode-visual scripting).

    but the Alpha Raycaster extension is good for the price.
    i may buy it when i need it later.
     
    Last edited: Apr 4, 2015
  14. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    Well, yes, those 90% off icode were indeed appealing :) However, with my base price of 10$, I am not sure I will be able to make such huge discounts.
    By the way, the price for the next 1.4 version will be 15$, so effectively current deal is about 70% off, if you consider buying it later ;)
     
  15. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
  16. silverlaine

    silverlaine

    Joined:
    Apr 8, 2013
    Posts:
    8
    Hello, great plugin :) Works fine so far for most of the cases, but I stumbled upon a problem when I changed the pivot point of the RectTransform to (0,1). It gets offset and basiclly doesn't work. I'm trying to fix it on my own for now, since I need it fast.
     
  17. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    Hello, I was able to reproduce the problem and currently working on the solution. Will send you the hotfix ASAP. Sorry for the inconvenience.
     
    silverlaine likes this.
  18. Sule

    Sule

    Joined:
    Oct 29, 2013
    Posts:
    1
    Hi!

    I've encountered the same problem with the pivot.
    Do you plan to have a new release soon with the support for it?

    Otherwise great plugin :)
     
  19. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    Hello! Actually, I've submitted the new version with the fix a week ago, but it's still pending review.
    I can send you the new package, just PM me with your e-mail and invoice number.
     
  20. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
  21. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
  22. unicoea

    unicoea

    Joined:
    Feb 18, 2013
    Posts:
    39
    Hello!
    I test alpha raycaster in unity,when it deal with ARGB16bit or ARGB32bit sprite,it's works great in every platform, but when i change Texture format to RGBA compressed DXT5, it' will be ok in android, But it will fail on IOS and the program will be very slow for this error, Below is error message:

    x == 0 && y == 0 && blockWidth == dataWidth && blockHeight == dataHeight
    AlphaRaycaster.cs
    231:
    // getting targeted pixel from object's texture and evaluating its alpha
    float alpha = objTex.GetPixel((int)(texCorX + texRect.x), (int)(texCorY + texRect.y)).a;

    I test alpha raycaster v1.4a and v1.5. Hope it will be fixed.
    Thank you!
     
  23. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    Hello,

    iOS doesn’t support DXT, so it will auto convert the texture to PVRTC, which would require it to be square (width == height) potentially causing the error you provided.

    You may consider combining the textures to a square atlas, or disable compression for iOS builds.
     
  24. unicoea

    unicoea

    Joined:
    Feb 18, 2013
    Posts:
    39
    Thank you very much!
     
  25. amyHelloWorld

    amyHelloWorld

    Joined:
    Jun 5, 2015
    Posts:
    6
    hi
    I am using the graphic raycaster and it is really good.

    I have got it to disable my interactivity when over ui elements, but Ihave 2 problems, when you :
    -Change the anchor presets to use any stretch, it can't seem to figure out where the alpha is anymore
    -Use preserve aspect in the image component. I just get the same problem as changing the anchor prest to stretch
     
  26. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    Hello,

    I was able to reproduce both issues you’ve described and is currently working on the solution. Will send you new version with the fixes soon.

    Sorry for the inconvenience.
     
  27. amyHelloWorld

    amyHelloWorld

    Joined:
    Jun 5, 2015
    Posts:
    6
    no problem thank you for looking into it
     
  28. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
  29. afoutsjr

    afoutsjr

    Joined:
    Aug 15, 2012
    Posts:
    7
    We have begun utilizing the "crunched" texture option introduced in a recent update of Unity. This particular format has been very helpful in reducing the file size for our Web Player and WebGL builds. Unfortunately, Alpha Raycaster does not appear to be working with "crunched" textures. Are we doing something wrong? Does Alpha Raycaster support "crunched" textures?
     
  30. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    Hello,

    It’s not the limitation of the Alpha Raycaster itself, but the Unity’s GetPixel() function. It’s not currently working with the crunched textures and I can’t really do anything with it, sorry. I hope they will fix that in one of the future updates.
     
  31. amyHelloWorld

    amyHelloWorld

    Joined:
    Jun 5, 2015
    Posts:
    6
    HI

    I have attained the latest version of the AlphaRaycaster and added it into our project. I am still having an issue with Sliced and Tiled sprites where the alpha raycaster cannot detect the true alpha of a pixel correctly when the sprite itself has changed shape and size from its originally texture resolution.

    Can you advise what solution can solve this?

    Regards
     
  32. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    Hi, sorry for the delay. In the previous post you’ve mentioned issues with anchored presets and preserve aspect mode, which were both fixed in version 1.6.
    I’ve just checked the case with tiling and stretching and was able to reproduce the issue. Will send you new version with the fixes as soon as it’s ready. Sorry for the inconvenience.
     
  33. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    @amyHelloWorld

    Version 1.7 with sliced and tiled sprite modes support is ready and pending review on the store. It should be live in about a week or two. If you need the new version right now, you may get it here: https://get-asset.appspot.com/AlphaRaycaster (you’ll be asked to enter invoice number in order to download the package)
     
  34. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
  35. Hilbert

    Hilbert

    Joined:
    Dec 3, 2014
    Posts:
    10
    Great asset!

    One minor issue I ran into when using sprite atlases (the ones Unity creates automatically from packing tags): I had to replace
    var texRect = objImage.sprite.rect;
    with
    var texRect = objImage.sprite.textureRect;
    in order to make it work correctly.
     
  36. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    Thank you for reporting the bug! I’ve actually used sprite.textureRect in the past, but it turned out Unity internally trims sprites with redundant transparent space so I’ve switched for the sprite.rect, as it was providing more accurate texture size and coords. However, seems it’s not working with the packaging system. Guess I will have to handle “redundant” and normal sprites differently.
     
  37. DTo

    DTo

    Joined:
    Sep 2, 2014
    Posts:
    5
    Hi I've just gotten your plugin from the asset store and I have currently having problems and I hope that you can help.

    My project requires me to create buttons by loading in 2DTextures from WWW and not from the Project Folder. (I am not allow to use the Project Folder)

    Because of this I cannot enable The Alpha check script. I have been getting this error in the Inspector's Alpha check component. It does have a Source Image how do I go about fixing this?

    Thank you.
     

    Attached Files:

  38. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    Hi,

    If I understand correctly, you are loading the textures at runtime via web? If that’s the case, then you may just ignore the warning (or assign a temp texture to get rid of it). If you need to configure AlphaCheck component for a specific texture, you may do this at runtime. Also, make sure, that the textures you are using are readable.
     
  39. DTo

    DTo

    Joined:
    Sep 2, 2014
    Posts:
    5
    Thank you. I've just created a WebGL build with it and it's work exactly as it should. However it doesn't seem to work in the editor at runtime, all buttons are acting as a square. but the build is most important.
     
  40. ltethe

    ltethe

    Joined:
    Jan 21, 2014
    Posts:
    6
    Unsupported texture format - needs to be ARGB32, RGBA32, BGRA32, RGB24, Alpha8, RGBAFloat, RGBAHalf or one of supported compressed formats.
    UnityEngine.Texture2D:GetPixel(Int32, Int32)
    AlphaRaycaster:Raycast(PointerEventData, List`1) (at Assets/AlphaRaycaster/Scripts/AlphaRaycaster.cs:330)
    UnityEngine.EventSystems.EventSystem:Update()

    This is killing me. I have a bunch of buttons and they're set to RGBA32, but the error persists. Despite this format, their performance on iOS is iffy at best. Works fine in the Unity Editor (5.4.1f)

    I'm not sure if this is related, but I feel like this error started when I was doing the atlasing of some other unrelated textures.

    And is there a best practices format for images that should be delivered to iOS, because I haven't found the secret sauce yet.
     
  41. ltethe

    ltethe

    Joined:
    Jan 21, 2014
    Posts:
    6
    Ok... I had ticked the override for iPhone flag on texture import settings for PVRTC... That was what was throwing the error. Not sure how it'll respond when I do a iOS build, but the errors are gone for the moment.
     
  42. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    Hello,

    Usually PVRTC compression is used for the iOS with textures combined to a square atlas.

    The method that is causing the error in your case (UnityEngine.Texture2D:GetPixel) is Unity internal API – seems like a regression of some sort, as it worked ok with PVRTC in the past. I’ve also found mentions about the same problem on the Issue Tracker: https://issuetracker.unity3d.com/issues/getpixels-from-etc-and-pvrtc-textures-doesnt-work

    While they are fixing the issue, you may try using other compression types. Here is a full list of supported texture formats for iOS: https://docs.unity3d.com/Manual/class-TextureImporterIos.html

    You may also consider downgrading to Unity version, which is not affected by this bug.
     
  43. fastgamedev

    fastgamedev

    Joined:
    Mar 27, 2014
    Posts:
    61
    Hi,

    Just bought the asset. Nice, it works, thank you.

    I believe there is a bug when enabling "preserve aspect" option:
    1. Import a texture with multiple sprites.
    2. Create a GameObject with an Image component. Set image source to one of the sprites from the texture. Enable "Preserve Aspect".
    3. Set width and height on the GameObject such that there is plenty of extra space inside that's not occupied by the Image sprite. (For example, if image sprite is 100x50, set GameObject to 100x100).
    4. Result: That extra space is a target for raycasts.
    5. Expected result: That extra space should not be a target for raycasts.

    Thanks.
     
  44. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    Hi fastgamedev,

    Thanks for reporting the bug, but unfortunately I wasn’t able to reproduce it.

    Here, I’ve recorded it:



    Tried Unity 4.6 and 5.4.1 versions. Maybe I’m doing something wrong, or you have some specific camera/canvas setup? If you could share a repro project – that would help a lot!
     
  45. Arctous

    Arctous

    Joined:
    Aug 25, 2014
    Posts:
    7
    Has 5.5 been tested? If so, are there any known issues?
     
  46. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    I've tested 5.5.0f3 version -- everything seemed to work fine.
     
  47. Arctous

    Arctous

    Joined:
    Aug 25, 2014
    Posts:
    7
    Great! Thanks!
     
  48. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
  49. elpeedros

    elpeedros

    Joined:
    Jun 6, 2013
    Posts:
    8
    Does this support VRTK? Specifically, I'm using the VRTK_UIPointer to interact with UI elements in VR, but it will trigger a hover on the rectangle. I'd like it to work like this asset. Thank you.

    https://vrtoolkit.readme.io/docs/vrtk_uipointer
     
  50. Elringus

    Elringus

    Joined:
    Oct 3, 2012
    Posts:
    137
    It should work as far as input is handled with Unity's EventSystem and GraphicRaycaster (upon which AlphaRaycaster is build).