[ad_1]

I wrestle to know greatest practices relating to composition and inheritance for Actor Elements in Unreal Engine 5. Concretely, I need to construct a base class, say Interactable that handles fundamental performance of interactable gadgets within the stage. E.g. it detects collision, creates a immediate saying “Press [E] to work together”, after which triggers an occasion or operate when this occurs. Subclasses can then implement this concretely.

Now, once I implement Interactable as an Actor, it is all simple. I can add a Field Collision to the scene root and hearken to occasions triggered by it. Nonetheless, this looks like a foul follow, as a result of an Actor then all the time ever be both Interactable or, say, Destructible.

It happens to me that Interactable ought to reasonably be an Actor Part as an alternative. Nonetheless, an actor element can neither have nor be a collision field. They can not have a collision field as a result of parts can not have parts. I really feel it needs to be doable that they will be a collision field, however no less than for Blueprints I do not see a solution to obtain that. It appears the superclass needs to be one thing like UBoxComponent. Nonetheless, this isn’t obtainable from the “New Blueprint” dialog. (Why?) The bottom ancestor is PrimitiveComponent, however that, too, can’t be chosen as a blueprint mum or dad class. (Why?)

The one methods out I see are:

  • Require that any Actor who desires to make use of the Interactable element additionally outline a collision field. Then, within the element code of Interactable I can look it up and register occasions with it. This places pointless burden on the consumer and appears very odd.
  • When the Interactable element is constructed, add a collision field to the mum or dad actor programmatically. This appears equally odd to me, and once more isn’t consumer pleasant as a result of it won’t be seen within the UI.
  • Use C++ I suppose? I might be tremendous with that in precept, but it surely appears this process is so easy that it lends itself nicely to the Blueprint idea, and I might be stunned if this actually solely works in C++.

Is there a greater one?

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *