Hello. I am doing my own VR game and I’ve got some problem. I am doing flashlight right now and I want to do charge showing on the flashlight. To do it I created a widget to shot the charge, but I don’t really know how to cast value to the flashlight. Like, I can’t understand what do I need to make as object
Maybe use blueprint interfaces. they allow you to send messages between blueprints.
it should be the other way round - the flashlight should create the widget so it always has access to it. This way you do not need to cast or use an interface. And you can have a bunch of flashlights, each with its own charge - if that is even at all needed.
The flashlight handles the charging process and then shows the resulting progress in the widget. Wouldn’t this make more sense?
Yes, thanks, more sense, really. But I don’t really know how to do it
Since you’re doing VR, you’ll be relying on widget components, right? Add the component to the flashlight actor. Something close to:
- in the widget:
- in the flashlight actor:
Call Start Charging
when needed.
Components are various bits that make an actor, think of them as of small parts:
A Static Mesh Component
is a component that displays a static mesh, for example. In VR screen space widgets do not work so well so Widget Components
often display regular widgets in 3d space instead.
You can see it in my previous post - where the green arrow is. The flashlight actor has a widget component attached to it. That component then creates the widget.
Some reading, just in case:
In the custom event, in the widget you have “In Percent”, how did you do it?
And in the flashlight actor you have “Set W Flashlight”, what is it?
Thanks for explanation
- flagged the progress bar as variable so it can be accessed:
- you can drag a wire from the pin and:
- custom events can be added like so:
You can add attributes and then called from some place else. It can be automated, too:
And in the flashlight actor you have “Set W Flashlight”, what is it?
it’s a reference variable, I accessed the widget component’s widget and assigned its value to a variable so it can be used elsewhere:
You can automate the process of variable creation by right clicking pins and promoting - works for pretty much any pin and saves oh so much time…
I did everything, it works well, but… I can’t understand how to make it decreasing charge
Pretty much the same as charging:
You will need to add more bits to this but that’s the general idea. You could probably reuse the same timer for both. Either add or remove charges. Wrap things in functions to organise it better.
If you ever look for inspiration on how to approach things (or a full tuts), consider punching what’s needed into YT:
https://www.youtube.com/results?search_query=ue4+flashlight+battery
You’d be surprised in how many ways can the wheel be reinvented.
And now I don’t know when I need to use them. I have some “code” which was working with my try, but now, I don’t know where to use them.
And the flashlight needs to be turned off when it has low charge (like 10%)
TSYM, Everynone. I will send you the result tommorow if you want me to do it. BC my Oculus Quest 2 ran out of battery and I want to sleep
Aw, I have a problem
Now it is working like this:
Can’t help without seeing the script.
But perhaps you’d want to investigate slowly on your own. You must understand how it all works, right? How the data flows and so on. Otherwise you’ll be stuck at every step.
At a glance it looks like it’s connected the other way round. You charge the battery when the light is on.
I will try to fix it on my own
Oh, I see the problem.
When it activates Drain Battery, it stops showing the charge in the widget, but I don’t know how to fix it
The script:
UPD: I solved the problem. TYSM for your help
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.