Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Easiest way to have a transparent gameobject hide portion of a sprite by masking it?

Discussion in '2D' started by CarterG81, Oct 17, 2014.

  1. CarterG81

    CarterG81

    Joined:
    Jul 25, 2013
    Posts:
    1,773
    SOLVED: Easiest way? Buy See-Through System for $30.

    ---------------------------------------

    I'm trying to hide specific sprites by simply placing another gameobject over it.

    This is extremely easy, if for example, you use a non-transparent square, it will obviously cover the sprite.

    What I want to do though, is for that same square to be entirely transparent, but still mask the sprite.


    circle.png


    I tried googling this, but it started to get a bit complicated. I was thinking there might be a very simple way to do this that I am just missing.

    The goal is to have "GameObject2" be transparent, mask all gameobjects on a particular layer (Characters, or what would be "GameObject1"), but not mask all layers (obviously it doesn't mask the "Money" gameobject).

    Anything I could simply buy from the asset store is also acceptable, to save myself time from having to do this myself, if it's too complicated to do quickly.
     
    Last edited: Jun 10, 2016
  2. Lisa C

    Lisa C

    Joined:
    Jan 26, 2014
    Posts:
    9
  3. CarterG81

    CarterG81

    Joined:
    Jul 25, 2013
    Posts:
    1,773
    I am not entirely sure what you mean? I need to be able to move around GameObject2, and anywhere it goes it should mask GameObject1. In effect, I need to use GameObject2 to "hide" pixels, but just specific sprites or layers (not the background, which is just a different sprite on a different layer).
     
    Last edited: Oct 17, 2014
  4. CarterG81

    CarterG81

    Joined:
    Jul 25, 2013
    Posts:
    1,773
    Alright, I believe the answer lies somewhere in shaderlab : Stencil.

    http://docs.unity3d.com/Manual/SL-Stencil.html

    I was reading about the stencil effect from this answer by supernat :

    http://answers.unity3d.com/questions/590800/how-to-cullrender-to-through-a-window.html

    However, I just read that "Masking was made super easy" in the new GUI 4.6, which I have.

    Both seem to work well for the OPPOSITE of what I'm looking for. All of these would allow GameObject2 to only be shown when it hovers over GameObject1. What I need is for GameObject1 to be masked when GameObject2 hovers over it.

    One alternative hacky solution I already have, which is so far the easiest, is to use the stencil effect, but and just gameobjects to be placed everywhere EXCEPT where I want it to mask. (It's a pretty bad way to do it, but unless I can figure out an easier way, I might stick with this until later.)

    edit: Nevermind, this wont work either, because I can't go full transparency.
    Looks like there is no easy solution. I really don't want to have to learn shader lab though >.< So much valuable dev time.
    bleh.png
     
  5. Lisa C

    Lisa C

    Joined:
    Jan 26, 2014
    Posts:
    9
    I mean that you make a material (which is the same shape as your object 2) on object 1 which acts as a mask for the texture on object one. With materials, you can specify the the offset, so this could move in the same way as your object two is doing.

    Think of it as kind of a shadow passing over your game object 1 and changing it's color. :)

    Sorry if I'm confusing you even more hehe ;)
     
  6. ImFromTheFuture

    ImFromTheFuture

    Joined:
    May 21, 2015
    Posts:
    30
    Hi,

    What did you use in the end? I'm trying to achieve something similar as well. I really loved the "Stencil" thing. I'm checking it out now and see if I can work with that. I'd like to know what did you use?

    Thanks
     
  7. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Stencils would do it. But you could also solve this pretty easily with a depth mask.
     
  8. CarterG81

    CarterG81

    Joined:
    Jul 25, 2013
    Posts:
    1,773
    Sorry, I have absolutely no idea what I ended up doing. My memory is not very good anymore, especially on technical stuff I haven't messed with for a very long time.

    I honestly don't even remember what I needed this for. I assume it was for Away Mission & not my current project... lol...

    Oh yea, I think I remember now. I was using it for a prototype of a mini-game for a specific profession to scan an area for hidden objects. (The player, like in Papers Please, would use a scientific device from the Medical Officer to scan for Micro-Organisms, using their Mouse/Finger)

    microorganism.png

    I don't know if I got this working or not. I know I came close if I didn't, but either way I am at a complete memory loss. And the project is buried, so I can't easily dig it up. I wouldn't even remember what folders to check into without taking some time to remember everything & get back up to speed.

    Whatever I ended up doing, I think I had some issues with it still. I believe I had to just move on without a satisfactory solution. It was working, but had some annoyance.

    --------------------------------------------------------------------------

    In my current project, I didn't even remember I did this with Away Mission, so I started from scratch. Before doing anything myself, I just browsed the asset store & immediately purchased this:


    It was only $30, highly rated, and had multiple applications for my game, so it was a no-brainer for me. The time it would take me to dig through how to do this & implement it is certainly worth far more than a meager $30. I'll just not eat out one night & save the headache.

    And I can use this for more than just one application, since my game is a perspective Camera with 2D Sprites in a 3D World.

    Worked immediately, extremely well. Love it. Highly recommend.
     
    Last edited: Jun 10, 2016
    JoeStrout likes this.
  9. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    @CarterG81, I liked your post for the pragmatic and helpful advice it contains... but, on an unrelated note, was saddened to hear that Away Mission is buried. Just FYI. :) I hope you bring it out again someday, because I still think it was a great idea!
     
    CarterG81 likes this.
  10. CarterG81

    CarterG81

    Joined:
    Jul 25, 2013
    Posts:
    1,773
    Thank you :)
    No doubt, I will resume Away Mission the moment I am finished with my current project. Every day I yearn to start back up on it. I absolutely love it & really want to play it myself. There's no way in hell I won't finish Away Mission ;)
    It'll just take a bit more time, hehe.

    I put it on pause so I could get more experience with a different game. That way I learn from my mistakes & can make Away Mission even better. I didn't want it to be my first game, and thus suffer from "first game" flaws. Especially when so many people wanted to play it too, but I figured pausing the project (something I don't take lightly) is worthwhile for everyone.
     
    JoeStrout likes this.