I would like to decouple a dialogue component from the pawn so that I just have to add the component and things work without almost no effort. However, for runtime lipsync, I need a reference to the skeletal mesh component of the owning actor. I thought I could expose a variable in the component so that I could select the mesh component of the owner that is resposnible for the lip animation. However, I cannot select the skeletal mesh component in the component.
Is there a way how I can make this happen?
The pragmatic version would be to get the first skeletal mesh component of the owner in the beginplay event. I just wondered whether there is an even better solution.
The pragmatic version would be to get the first skeletal mesh component of the owner in the beginplay event.
Have the component reach out to the Owner and pull what is needed, yup. You could even use an interface and ask the owning actor for a reference, so the owner can decide which SMC to feed to the dialogue comp in case there’s more than one.
I thought I could expose a variable in the component so that I could select the mesh component
This would be a great feature that has been requested more than once, but is unlikely to happen due to the way actors (re-)instantiate components. The best you can do:
I’m probably missing something. But what is the advantage of using the dispatcher instead of directly calling the CustomEvent function in the component?
Here, it’s just an OK use scenario; OP asked for options. But:
imagine something destroys the component, without a dispatcher you’d need to isValid every event call. Dispatchers do not care about who is listening, they just broadcast. And listeners can unbind freely, too.
you can bind dispatcher to many listeners. And then call the dispatcher once. You can Begin Play and bind 1000 delegates, then call once rather than do a 1000 ForEachLoop calls every time. It becomes surprisingly performant all of sudden taking into consideration how sluggish iteration is in BPs.
the approach shines when things are instantiated dynamically
What I’d really do here is to have the component reach out to the owner and look up a dispatcher to hook up to rather than rely on the actor to do it. This way, you can start dropping components left right and centre on any actor. If those actors contain what the component is looking for - great; if no - we don’t care.
But again, depends on what you’re up to. Pick best tool for the job. If you do not mind a tight coupling, just call a Custom Event directly, sure!