Download

Design Question: Multiple Components vs Multiple Structs.

This is a design decision question. As a “getting to know Unreal” project I am implementing a simple airfoil simulation, where an Actor can have multiple airfoils (wings, rudders, sails, keels) attached to them. Each airfoil calculates lift and drag relative to the flow around it and provides a Force and a Location to apply that force. Each airfoil has it’s own properties that determine Drag and Lift coefficients, including a reference to an associated bone to determine Angle of Attack… Each airfoil must access the Actor to determine it’s own world rotation and relative velocity.

I am trying to understand the implications of the various implementations

  1. One Movement Component, N Structs
    This is the way that WheeledVehicleMovementComponent handles it. There is one movement component that iterates through a struct per wheel. Each struct contains all the unique wheel or airfoil data, and points to a blueprint with further settings. It’s somehow tied up with PhysX, so it’s not clear to me that this is the best approach for a more general solution.
    In my version, Movement Component Tick would iterate over each airfoil struct, and AddForceAtLocation for each, or do it’s own force summation and apply forces and torques once.

  2. N Movement Components
    This would be one movement component per airfoil, each applying AddForceAtLocation in it’s own Tick.

  3. A Blueprint Library Function
    No movement component, just a static C++ function for computing force and location. The forces would be applied in the Actor Blueprint…

Naively, option 2 (N Movement Components) seems the simplest to implement and most manageable for a Blueprint user. Option 1 might be better if I intend to have some sort of damping or “fly by wire” system where the MovementComponent adjusts the forces to make the vehicle more manageable. I can’t see any advantages to option 3, other than being the least “black box”

Any thoughts from more experienced Unreal users?

I’d personally go with option 1 as it allows you to keep your calculations centralized in a single location.

If I create an array of structs as part of movement component, can a Blueprint user access the individual elements on the Creation and Event graphs?

Of course as long as they’re USTRUCTs and the array is a public UPROPERTY

Thank you for your help. I was able to implement an array of structs on my component, and access them in blueprints. I do have one further question:

In Blueprints, how do I Set just one property of the struct? Reflection gave me appropriate Make and Break nodes for the structs. There is also a SetMembers node, but it seems to overwrite everything.

EDIT: oh, I may just have to hide the unused pins to prevent setting.
https://answers.unrealengine.com/questions/150158/bug-report-set-members-in-struct-solution.html