How do you reference a StaticMeshActor from within a character blueprint?
If it's separate actor you can create variable with actor and assign it with editor. And then you can do whatever you want.
answered Sep 08 '18 at 04:36 PM
to reference an actor that is outside of the character you will need make your own method to aquire the reference there is not one built in like there is for the level bp. this is because you could have your character in many levels but the other actor will only exist in one level. there are many ways to get a reference though so it shouldn't be too hard. I'll mention three methods here, public variable, traces, searching.
first comes the public variable method which is good for when you place your character in the level and the other actor already exists in the level as well and when its a set item that wont be changing. to make this setup you create a variable in your character then click the eye icon next to the variables name so that it appears open, this makes the variable public. the variable being public means that you can modify its value by selecting the character and changing the value in the default section of the details panel. the last step is to set the type of the variable, actor should be good to start but you may want to narrow it down to a more specific type later.
the next method is to use a trace. a trace basically projects something (usually a line or shape) from one point to another and tells you if it hit anything along the way. we can use this to project a line from the character to a point 500 units in front of the character and if the trace hots something it will be returned so we have a reference to it. think of it like walking in a dark room with a stick in front of you, then when your stick hits something it lights up so you can tell what it is. ill link the doc on it for you to peruse.
the last method can be a very good one when used correctly, but many people use it incorrectly which results in poor performance and unreliable results. this method consists of using something like the get all actors of class node which as you probably guessed returns all the actors of a specified class (you specify) as an array. you can then take this array and apply conditions to narrow down to the item you want. and example of this would be if you wanted to get the closest enemy to you character. then you could get all actors of class enemy, then you would take the array and run it through a loop which checks the distance from the character to the enemy and returns the one with the shortest distance. note though that you should never do as many people do and use a get all actors of class then a get index 0 node, this will not always return the same object making it unreliable and its a un-performant way to accomplish the task.
along the same lines as the get all of class there is also the get all with tag and the get overlapping actors.
answered Sep 08 '18 at 06:33 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here