Hello everyone!
I’m trying to make a simple thing: a flickering light component that can be reused with any Light component. I have several candelabra blueprints with flames as particle systems and I want to give the candelabras a movable point light with a subtle flickering. I don’t want to copy paste code, so that’s why I wanted to create a component. But I’m having some issues:
- I could make the component to inherit from PointLightComponent, but I’d like to be able to attach the component to other already existing lights, not to be a light by itself. Besides, if I wanted a flickering directional light, I would have to create another component and copy and paste the same code, right?
- I’d like to do it the Unity way: just to be able to assign any light component to my flickering component. But it seems that Unreal doesn’t let you reference components from other components. From what I’ve gathered reading the answer hub and the forums, that seems to be the case. If I create a public LightComponent reference, the editor only lets me assign assets in the project, not other components in the same blueprint.
- I could create the reference to the light in the blueprint itself, and then, from my flickering component, access the owner and then the reference. But what’s the point on having reusable components if you have to add code to the each blueprint anyway?
- And this is what I have right now: Since I’m not able to set a direct reference to the light component, I added to my flickering component a public string variable where I can enter the name of the light, then I access the owner, get all classes of type LightComponent in the blueprint, and then find the one with the specified name.
This method, as I said, is the one I’m using now and it works. But I don’t like it, because I find it ugly and having to compare strings and find components is not as performant as having a direct reference to the light.
So, for my situation what would you think is the best approach to deal with this with Unreal? Maybe there’s another way I’m not able to come up with.
Thank you very much for your attention!