Attach array of actors to another array of actors
Howdy! Well, i have a Spawn Volume that spawns randomly meteors all arround the spawn (its a spaceshp universe so there's no floor) and you have to shot the meteros and destroy them, pretty simple. The thing is that i want to add the life of the meteors, so you can see how many bullets do you need to destroy them. I've done this adding a widget into the meteor actor and update every time that the players looks at it, or shots, but its kinda annoying because the widget rotates randomly with the meteors (so, sometimes the hp bar is inside the meteor looking at you, or in a side, or behind, or you just can't see it... ) And what i want to do, is have this hp bar just up in the meteor, looking at you, but i can't create this into the meteor bp (i think) because it will rotate. What i've done this far, is create another actor, which is only a widget, and try to spawn it the same times as the meteors, and then attach them into the meteors.. but is not working, and i think im messing up this. Thank you! And sorry for my english, its not my native lenguaje!
asked Apr 12 '17 at 08:34 AM in Blueprint Scripting
Adding a widget component to your meteor BP or attaching an actor with only one widget component to your meteor BP shouldn't make any difference. I would try to update the widget component world rotation at the tick event of the meteor BP. I don't know the local directions of your widget (i.e. is the x-axis point up, or right, ...), but you can create a rotator out of two axis. So when I assume that the widget's local z vector should point upwards and the x vector should point towards the player, then use the "Make Rot From XZ" node, plug in the global Z vector as Z and the player's world location minus the widget's world location as X, and use the rotator for Set World Rotation Of Component for the widget. I hope this helps.
answered Apr 12 '17 at 09:01 AM
You should try to see the results by using only a Widget and screen space. There are two ways to tackle this.
The first one is by simply using your main HUD class. Get all the meteor actors and project their world location to screen location so that you get the location in screen space where you will draw their health bar. You can additionally filter by their position on the screen so any meteor that is not on the screen will be left out. You could also move the health bar above the meteor (in your case in screen space since they're rotating in world space). Example:
The second is a bit more complicated. You should create a separate Widget that will contain the health bar itself, and then in a similar fashion spawn it above the meteors, but this time from your main HUD widget. You should create a canvas element that has full screen size in your main widget and then on construct spawn the health bar widgets and parent them to the canvas. The health bar widgets should have an actor variable (could also be meteor) that should be passed on spawn, which will be the connection between the widget and the meteor actor. Then in the health bar widget on tick just take the actor location project it to screen space and translate the health bar element to that position. You could also filter this position as it may be off screen.
I haven't tried this yet on this specific example, and I don't have the time now, but it has worked for me in the past. If you can't figure it out by yourself I will post a blueprint screenshot later.
Follow this question
Once you sign in you will be able to subscribe for any updates here