Abstract The lightweight design of hydraulic equipment has always been of vital interest. Additive manufacturing (AM) technology can meet the manufacturing requirements of heteroideus and lightweight hydraulic equipment. However, traditional layout optimization often cannot satisfy the functional constraints of hydraulic components. This article proposes a design method of function-based automatic layout optimization for hydraulic components to solve this problem. The proposed method combines multi-component layout optimization with flow-up channel path planning and uses the triangular mesh model of hydraulic components directly as layout units. The spatial pose of the layout unit is used as the gene sequence for a genetic algorithm (GA). To meet the functional constraints, this study also proposes a fast, accurate collision detection algorithm for irregular 3D models and the generating strategy for follow-up flow channels. Here, the volume of the layout units, the total centroid radius of the layout plan, the length of flow channels, and the pressure loss are taken as the objective functions, and an automatic layout optimization algorithm for hydraulic components is developed. By optimizing the initial layout plan of an aviation electro-hydrostatic actuator (EHA), the characteristic volume of the optimized layout is reduced by 30.68% and the total length of the flow channels is decreased by 39.53%, demonstrating the efficiency of this method for lightweight hydraulic equipment design.