How do I hide components in front of my character in a top-down view game?

Good time of day,

What I do want to do is to hide things like walls and roofs (and floors also) if they are colliding with player camera / visibility.

So far I’ve found 3 possible solutions / ideas to this:

  1. Use Level Streaming which is not nice (purpose of it is much more different as I understand);

  2. Use rays, which also seems to be problematic whenever you have a complex actor in scene (say a blueprint of building which is made of several actors), as rays just hide whole actor (which is building). However rays are going to be good if purpose is just to hide several not connected objects;

  3. Use triggers inside blueprints, which gives a really nice tuning (ex: we have a building and triggers inside it which configured to hide walls, floors, roofs depending on player location). However if you will rotate building by 180 degrees you will have to reconfigure all triggers, which is not good at all.

I haven’t yet seen any real nice solution to this and therefore would like to here your thoughts on this (or may be even solutions if you have some).

I’m still new to engine and if I’m misusing some concept’s idea (like Level Streaming) I apologize:)

Anyway, thanks in advance

Hey ,

Level Streaming isn’t a good solution for this, as it actually loads and unloads assets inside level, and excessive use of this will cause some hitching in your game, and will likely have a higher processing cost than is necessary. Using trigger volumes could work, but as you mentioned it’s not a very modular approach to your design and would cost you in time.

Using a line trace or capsule trace is best way to handle this. With some creative setup, these line traces can be used even in situation you described. Here’s an image of how I set this up in my top-down project:

12325-hideprimitivecomponentslinetracebychannel.png

What I have here is a Multi Line Trace by Channel between a sphere component I put on my character’s head and character’s camera. It does a quick check to see if it’s hitting anything, and assigns everything it’s hitting to a temporary array. I do a ForEachLoop to check each Actor hit, use Break Hit Result to get every Component hit, and set it Hidden in game. ToggleHiddenArray is just to keep track of what I’ve set hidden, so when there’s nothing being hit it sets hidden to false.

In this scenario, we’re taking Hit Component instead of Actor, so in a case where you have a Blueprint with multiple components it will only hide components crossing line trace and not entire Actor.

This isn’t a perfect setup. For example, you’ll likely need to add checks so that it un-hides components when they’re not in line trace rather than when nothing is in line trace; as it is, components won’t be un-hidden until character moves to a place where nothing is in between character and camera. Still, this is a good starting place.

You may also need to play with Visibility collision settings for your Actors, Components, etc to make this work.

Hope this helps! Let me know if you run into questions with it.

Hello,

Well, this brought some good results, but also some bad ones:)

First one, for aiming I’m using “Get Hit Under Cursor by Channel” which works fine, but whenever I’m in building it seems to be aiming hidden floor above (so that when I’m aiming right top corner player aims just right or to bottom right). “Convert Mouse Location to World Space” would probably work but it works incorrectly for camera under angle.

Second one are shadows which also disappear when component gets hidden, may be I just did wrong setup for components.

Any ideas for these ones? Anyway thanks for help! At least I got some point to start.

You would need to use a different Trace Channel in your Get Hit Result Under Cursor by Channel than you are for your Line Trace. So if you use Visibility for one, use Camera for other (that’s how mine is set up, as well). You’re also able to set up custom Trace Channels in Project Settings > Collision, which will update nodes to include your new channel.

You can set any Component or Actor to show shadows while hidden, using Cast Hidden Shadow option. For a Static Mesh Actor in your level, you can access this in Details panel under Lighting. For a Blueprint, you can select all components you would like to cast a shadow while hidden, and apply setting in Details panel in Components tab.

That works, thank you for your answers and time.

Hey, so I’ve managed to set it up so that assets blocking line of site to character are set to a glass material, making them see-through rather than just entirely gone, but I can’t figure out how to get material to set back to it’s original…

Hey, so I’ve managed to set it up so that assets blocking line of site to character are set to a glass material, making them see-through rather than just entirely gone, but I can’t figure out how to get material to set back to it’s original…

I realize this discussion is long over, but wanted to add my own solution to problem for posterity’s sake.

It’s kind of tedious, but I use a blank actor class for each level. Then every actor on level 1 is a child of Level1ParentActor class. So when my unit was on level 2, for instance, all actors of class “Level3ParentActor” and “Level4ParentActor,” etc … get set to hidden. When switching to another unit or moving that unit away from level2 all those actors are un-hidden.

This can also be over ridden by UI buttons.

My inspiration was original XCOM games where camera level could be set to show only levels below whatever current camera level was. (Of course camera doesn’t actually change levels, it stays in same place. It’s just a variable used to decide which levels to show/hide.)

From reading comments above, I think I might have done it a bit different, but it worked.

tedious part is ensuring that every actor in map is made from its appropriate parent.

I wonder now if this could be accomplished using level streaming, where entire levels are hidden based on camera’s current level.

1 Like