I just looked into your project, thank you… I’ll try all that by myself, I think you gave me enough informations. Thank you again
Hi, I managed to have a result, I have two questions, I’ll begin with the first one:
Will I have to make a new sequence pin for each light in the panel as we are casting to one actor? Because I think it’ll get awkward if I have several lights
(this code is in the player controller)
Here’s the code in the light actor itself:
For now it works.
The above looks very OK at glance. Nice.
Nah. This can be solved in many ways, depending on how complex things eventually become (a rule of thumb is to expect the worst). This can even be done without casting. You’ll need to explore 2 areas:
- inheritance
- interface communication
Ideally both as they can be used at the same time.
Start with inheritance - it’s a parent-children relationship; here’s an example:
- a basic lamp and 3 children lamps:
- the children inherit variables and functionality from the parent:
This script is only in the parent blueprint but all children can use it, too.
- one of the children lamps is special, it has 2 lightbulbs (one inherited from the parent and an additional one):
And now, with the above setup in mind, were you to cast, you could:
…cast only to the Parent - this will work for ALL children lamps that inherit from the base class. Not only would this switch any lamp on, but it would also execute the unique functionality of the special lamp with 2 light bulbs. And the parent does not even know about the second light bulb in one of the children.
So no, you wouldn’t need to cast to every lamp - just to the parent one.
Interface communication allows you take things event further and either limit casting or avoid casting altogether. If you wanted to send a message to many unrelated actors, you’d use an interface.
Imagine you have a USE
UI button and you walk through a house. If you click USE on a lamp, you’d expect it to switch on. But if you USE a garage door, you’d expect it to open.
You can send a generic message through an interface to any actor - and it will be the actor’s job to decide what USE means and act appropriately. Powerful stuff!
Thanks! I’ll look into Interface communication and parent/child actors.
My second question is that currently we create the widget in the Player Controller, so it opens when I launch the game. I’d like it to be as it’s previous state, which means open itself only when I click on the “Edit” button in my main UMG. Do I have to use blueprint interface to do this?
Up to you really. You can keep it in the PC, you can create it in the main widget. A better question is: “why don’t you create the main widget in the player controller in the first place” This way you’d have all the necessary stuff in one location reachable at all time from (almost) anywhere.
which means open itself only when I click on the “Edit” button in my main UMG.
Any widget can get player controller
and ask to open a (existing) widget. Or, if you decide to create it in the main widget, you could do it like so:
Here, one widget creates (and controls) another. And the new widget is hooked up to a Custom Event in the Player Controller.
At this point, you could even access the Selected Actor here in the widget, if you wanted to. But scripting too much in the widget makes things awkward rather quickly. But it can be done.
Another thing to consider is whether different pieces of furniture should have different widgets! Maybe sofa’s widget will be very different from TV’s widget. Perhaps it’s the lamp, sofa, TV that should create and hold onto an Edit Me widget each. Again, it really depends on the end goal.
Because at the beginning I didn’t have the knowledge I have now thanks to you, and it’d be a pain is the … to change it all now…
What if I want to keep creating it in the PC, how do I tell it to open the created widget only when the right button is clicked in the Main UMG ?
Also, do you know why the light turns off when I click it and why it reactivates when I toggle the SECOND slider? no matter with which I start, it will activate with the second
- create it once, hide it:
- your main widget can now ask the PC to show the edit widget:
only when the right button is clicked in the Main UMG
You’d override onMouseButtonDown
and do the above. Just don’t try to right click native buttons, you will have a bad time.
Probably because of this:
What is the default value on the custom event?
If it’s 0, the Begin Play would set it to that zero value as the custom event has yet to be run. This is probably not too safe to begin with. Maybe have the Begin Play call the custom event with the desired value. Or do not call it at all.
At this rate I will pay you for these lessons you give me!
Thank you AGAIN, you make my work so much easier.