Getting blueprint class for each other component instance without hardcoding path.

Hello. I’m trying to make an InteractiveComponent, which creates class derived from UWidgetComponent. In this component I want to show widget created as UMG (this is a suggestion to the player about interacting with the object). So I need to reference to one widget blueprint class in every instance of my InteractiveComponent.
I had 4 possible solutions:

  1. Mark as UProperty field of type TSubclassOf. But this way I would need to do this for each InteractiveComponent, which increases the likelihood of errors, and I think this is an illogical and inconvenient solution.
  2. Hardcode path to blueprint class. This is also a bad solution because class paths may change and you will have to manually change them.
  3. Create a GameSingleton class. This solution is already better, since it does not have the disadvantages listed above. But the disadvantage of this solution is that it is not possible to get this GameSingleton in the component constructor, which results in poor architecture and the need for runtime calls.
  4. Static variable. There are just my guesses and that would be a solution, but UProperty does not support static variables. But I need to set blueprint class from editor.
    That’s all that came to my mind the whole time. Guys, I would be glad if you could help me with this problem and I would like to solve it in the best possible way from an architectural point of view. Any help is welcome and thanks in advance.

I’d say make a UPROPERTY TSubclassOf, then make a BP child of the interactive component to point the property to the proper class. Then simply use the BP version of the component in your blueprints. You can maybe even mark the native component as Abstract to avoid using it in blueprints.

[Chatouille] Thanks so much! I discovered a new design pattern for my self - composition.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.