Hi. This is probably a super easy thing to set up but I just can’t get it to work and I’d appreciate some help.
I’m trying to create an AI Character that is invisible to begin with, but once looked upon by the player, turns visible.
Here’s what my blueprint currently looks like in my BP_Player.
Hi @StartingDev, this is a very interesting question. There is some solutions, but I want to provide the best that I know and to do that I have some questions.
For clarity, you want this ai to be invisible until the player hit’s the ai with the line trace correct?
Should the player be able to collide with the invisible ai?
If you can answer those questions, I might be able to provide some insight on how to make a system that your looking for. Thanks for your time!
yes, I want the AI to be invisible until the player hits it with a line trace, upon which it turns visable. I then afterwards want to be able to look away from it, upon which it once again goes back to being invisible.
@StartingDev
Thanks you for answering. This is very simple to make and you already did most of the hard work.
Here are the steps to get this working:
I recommend Line Trace For Objects instead of channel because your using the visibility channel and 99% of objects in the game world has the visibility channel as blocked so the line trace will detect everything even something as simple as the wall or floor which is not good. If you can’t use Line Trace For Objects for any reason, then create a custom channel and use Line Trace For Channel.
After casting to you Ai and checking for validation, you should also make a variable and set it to the casted actor so not the Hit Actor, but the actor you casted. (if that makes sense)
After step #2, you want to use the boolean return value from the line trace and use it in a branch node. The boolean return value from the line trace returns if something is hit. The code that you have already will go on the true pin and we will have some use for the false pin.
In the false pin of the branch you want to use the IsValid macro to check validation for the variable you set in step #2.
In the IsValid pin, you want to set the mesh visibility to false, THEN you want to clear the variable by setting it to nothing.
(MAY BE OPTIONAL)
You might run into some issues depending on your settings for your Line Trace node where the Ai does not go invisible. To fix this you need to hook up the functionality from step #3 - #5 to the pins as shown:
Recap:
If done correctly, when your line trace hits something it will return true which fires the true pin from the branch. In the true pin the Hit Actor gets casted and checked for validation before setting the variable and the AI’s mesh visibility to true. However, if your line trace does not hit anything, then the false pin of the branch will be fired which will hide the AI mesh and clear the variable.