Hey there!
This issue isn’t directly related to any of the courses at the moment, although I first ran into it while experimenting with them, specially #battle-tank and #building-escape. It kinda grew on me so I’ve been working on it as an independent “plugin”.
Sorry for the lengthy post, I’ve quoted the extra “backstory” parts in case someone doesn’t need much explanation.
TL;DR, I want to be able to send events from a component when its parameters are modified in editor, so that the actor containing them actually responds to them and shows the changes properly. It’s been surprisingly hard to do so in any intuitive way, and nothing I’ve tried works reliably.
I decided to experiment a bit and create some sort of interaction/activation system based on components so that they’d be highly modular. Basically, there’d be an “Interaction Component” holding all the logic necessary to bind player (or AI) inputs to allow them to interact with things, and an “Activator Component” which would then react to these interactions.
You’d place the first one on your pawn and bind input events to the “Interact” functions to be able to open/trigger things, and the second one in buttons, doors, keys, lights etc.
My main focus is this second one, the “Activator”. The component focuses on receiving inputs from the other one, but it can also be linked to other activators for chain interactions (like a button that opens a door, for example). The activator keeps track of a customizable number of states (so you can have stuff that opens/closes, locks/unlocks, turns on and off, etc.) and dispatches a handful of events to relay that state to the actor that holds the component. The events include tick-type versions so you can set stuff to interpolate directly from them without the need for timelines.
So basically, the designer would make a prefab blueprint for the interactable object, like the door, drop this component and hook the state events so that the door opens and closes on interactions.
The system performs decently, although I’m sure that I could have relied more on built-in stuff from the engine.
The part that doesn’t work so well is the fact that I couldn’t find a way to reliably reflect the designer’s tweaks to the component in the actor during editor work. Since the parameters are meant to be tweaked in a component, it’s been surprisingly difficult to make these changes to show up directly in the editor so that you can see how it looks without having to start the game.
I’ve tried so many things that I can’t even remember properly, but the three main attempts have been the following:
A) I’ve tried the obvious thing, which was to broadcast delegates directly from the PostEditChange() events. This doesn’t work, even though the delegates report that they are bound. I even tried to force the bound function call though hacky means (getting the UFunction pointer from the delegate and using CallFunction().
The closest I’ve gotten with this method has been to be able to trigger C++ functions in an owning C++ based actor. If I try to force call events or overridden functions in BP, nothing happens (apart from crashes when I touch something delicate).
B) I’ve tried to delay the delegate broadcast calls into overridden events that should happen later, hopefully after the actor has been initialized/updated enough to respond to them properly. The best candidate is OnRegister(), but unfortunately, this isn’t reliable. Specifically, it appears that the event is never called when the component is set to its default values.
The best I’ve managed with this one has been to add a dummy property so that there’s always an edited one even if the relevant ones are reverted to default. This is the solution I’ve settled with for the moment.
C) Out of desperation, I’ve also tried enabling in editor tick and see if I could at least brute force it to work by checking the actor state every frame and try to figure out a good time to broadcast the damn delegates. This didn’t work any better, since anything that I would use as a sign for the actor being “ready” usually happens in one of those overridable events anyways, so I’d be mostly doing the same in a much less efficient way.
From here, I honestly don’t know where to go. I assume that there must be ways to do this appropriately, maybe with an editor plugin or something similar, but I’ve got no experience whatsoever with that and the documentation isn’t exactly easy to follow past the common resources.