{"id":1134,"date":"2022-07-18T16:30:11","date_gmt":"2022-07-18T07:30:11","guid":{"rendered":"https:\/\/colory-games.net\/site\/?p=1134"},"modified":"2023-11-04T20:44:47","modified_gmt":"2023-11-04T11:44:47","slug":"ue-add-cpp-file-en","status":"publish","type":"post","link":"https:\/\/colory-games.net\/site\/en\/ue-add-cpp-file-en\/","title":{"rendered":"[UE5] How to Add or Delete C++ Files (Classes)"},"content":{"rendered":"\n<div class=\"wp-block-jetpack-markdown\"><p>*<strong>The content of this article is applicable to UE4.<\/strong><\/p>\n<p>&quot;I want to add a C++ file (C++ class) in Unreal Engine.&quot;<br>\n&quot;I was able to add files, but I don&#8217;t know how to remove them.&quot;<br>\nTo solve this problem, this article explains how to add\/delete C++ header files and source files(classes) in Unreal Engine.<\/p>\n<blockquote>\n<p>Note: In order to use C++ in Unreal Engine, you need to install Visual Studio 2019. If you have not setup the environment, please refer to the following article.<\/p>\n<\/blockquote>\n<ul>\n<li><a href=\"https:\/\/colory-games.net\/site\/ue_start_cpp-en\/\">[UE5] How to Introduce C++<\/a><\/li>\n<\/ul>\n<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">\u76ee\u6b21<\/p><ul class=\"toc_list\"><li><a href=\"#How_to_AddDelete_C_Files_C_Classes\">How to Add\/Delete C++ Files (C++ Classes)<\/a><ul><li><a href=\"#Method_1_Add_from_the_UE_editor\">Method (1): Add from the UE editor<\/a><\/li><li><a href=\"#Method_2_Adddelete_from_Explorer\">Method (2): Add\/delete from Explorer<\/a><\/li><\/ul><\/li><li><a href=\"#Summary_ProsCons_of_Each_Method\">Summary (Pros\/Cons of Each Method)<\/a><\/li><\/ul><\/div>\n<h1><span id=\"How_to_AddDelete_C_Files_C_Classes\">How to Add\/Delete C++ Files (C++ Classes)<\/span><\/h1>\n<p>When you create C++ classes in Unreal Engine (&quot;UE&quot;), you need to create C++ header file and source file (&quot;C++ file&quot;) which contains the source code.<\/p>\n<p><strong>There are two ways<\/strong> to add C++ files.<br>\nIf you want to delete C++ files, <strong>you need to follow method (2)<\/strong>.<\/p>\n<ul>\n<li>Method (1): Add from the UE editor.<\/li>\n<li>Method (2): Add\/delete from Explorer.<\/li>\n<\/ul>\n<h2><span id=\"Method_1_Add_from_the_UE_editor\">Method (1): Add from the UE editor<\/span><\/h2>\n<p>Open the UE project file (.uproject file) and <strong>Launch UE Editor<\/strong>.<br>\nSelect &quot;Tools&quot; tab &#8211; &quot;New C++ Class&#8230;&quot;, and select the class you want to add.<br>\nThen click the &quot;Next&quot; button (See below figure (1) to (4)).<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/add_cpp_editor_1.png?ssl=1\"><img decoding=\"async\" src=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/add_cpp_editor_1.png?ssl=1\" alt=\"Add from UE Editor 1\" data-recalc-dims=\"1\"><\/a><\/p>\n<p>Next, enter the file name (class name) and the save location (See below figure (1) to (2)), and click the &quot;Create Class&quot; button (See below figure (3)).<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/add_cpp_editor_2.png?ssl=1\"><img decoding=\"async\" src=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/add_cpp_editor_2.png?ssl=1\" alt=\"Add from UE Editor 2\" data-recalc-dims=\"1\"><\/a><\/p>\n<p>A C++ file is generated at the specified location.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/explorer_cpp_file.png?ssl=1\"><img decoding=\"async\" src=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/explorer_cpp_file.png?ssl=1\" alt=\"Save location of C++ files\" data-recalc-dims=\"1\"><\/a><\/p>\n<p>Return to the folder where the UE project file is located, open the Visual Studio solution file (.sln file) and start the Visual Stduio editor.<br>\nThe C++ file has been added to the Explorer.<br>\nNote that <strong>it automatically generates the minimum source code<\/strong> to define the C++ class.<br>\nAlso, you can find the file name is same as class name.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/open_vs_1.png?ssl=1\"><img decoding=\"async\" src=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/open_vs_1.png?ssl=1\" alt=\"Visual Stduio Editor\" data-recalc-dims=\"1\"><\/a><\/p>\n<p>Build (compile) the software (See below figure (1) to (2)).<br>\nIf the process ends normally, the compilation is complete.<br>\nNow, you can use the created C++ class on the UE editor.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/compile_1.png?ssl=1\"><img decoding=\"async\" src=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/compile_1.png?ssl=1\" alt=\"Compilation Method\" data-recalc-dims=\"1\"><\/a><\/p>\n<p><a href=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/compile_2.png?ssl=1\"><img decoding=\"async\" src=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/compile_2.png?ssl=1\" alt=\"Compilation Result\" data-recalc-dims=\"1\"><\/a><\/p>\n<p>Note that this procedure can add C++ files (classes), but can&#8217;t delete them.<br>\nAlso, you can&#8217;t <strong>move or rename C++ files<\/strong>.<br>\nIf you want to perform such operations, you must follow the  Method (2).<\/p>\n<h2><span id=\"Method_2_Adddelete_from_Explorer\">Method (2): Add\/delete from Explorer<\/span><\/h2>\n<p>Place the <strong>C++ files (.h and .cpp files)<\/strong> in the &quot;Source&quot; folder &#8211; (project name) folder in the folder where the UE project files (.uproject files) are located.<br>\nIt is also possible to place them in the child folders.<\/p>\n<blockquote>\n<p>Note: On this phase, you can add any data (source code) in the C++ files.<\/p>\n<\/blockquote>\n<p><a href=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/explorer_cpp_file.png?ssl=1\"><img decoding=\"async\" src=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/explorer_cpp_file.png?ssl=1\" alt=\"C++ File Location\" data-recalc-dims=\"1\"><\/a><\/p>\n<p>Return to the folder where the UE project files are located.<br>\nThen, right-click on the UE project file (.uproject file) and select &quot;Generate Visual Studio project files&quot;.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/right_click_menu.png?ssl=1\"><img decoding=\"async\" src=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/right_click_menu.png?ssl=1\" alt=\"Right-click on the .uproject file\" data-recalc-dims=\"1\"><\/a><\/p>\n<blockquote>\n<p>Note: If there is not a menu item &quot;Generate Visual Studio project files&quot;, please refer to the following article**.<\/p>\n<\/blockquote>\n<ul>\n<li><a href=\"https:\/\/colory-games.net\/site\/ue_start_cpp\/\">[UE5] Solution: The right-click menu item for uproject files does not appear<\/a><\/li>\n<\/ul>\n<p>Open the Visual Studio solution file (.sln file) and launch the Visual Stduio editor.<br>\nThe C++ file is added on the Explorer.<br>\nNote that the data (source code) in the C++ file remains as it was when the file was placed.<br>\nUnlike Method (1), you need to <strong>write the source code yourself<\/strong> from scratch.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/open_vs_2.png?ssl=1\"><img decoding=\"async\" src=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/open_vs_2.png?ssl=1\" alt=\"Visual Stduio Editor\" data-recalc-dims=\"1\"><\/a><\/p>\n<p>After you write the source code, build (compile) them (See below figure (1) to (2)).<br>\nIf the process ends normally, the compilation is finished.<br>\nYou can use the C++ class on the UE editor.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/compile_1.png?ssl=1\"><img decoding=\"async\" src=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/compile_1.png?ssl=1\" alt=\"Compilation Method\" data-recalc-dims=\"1\"><\/a><\/p>\n<p><a href=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/compile_2.png?ssl=1\"><img decoding=\"async\" src=\"https:\/\/i0.wp.com\/colory-games.net\/site\/wp-content\/uploads\/tech-blog\/beisaku\/2022\/07\/20220718\/compile_2.png?ssl=1\" alt=\"Compilation Result\" data-recalc-dims=\"1\"><\/a><\/p>\n<p>Note that the .sln file will be up-to-date after you execute the menu item &quot;Generate Visual Studio project files&quot; on the .uproject file.<br>\nAll changes on the C++ files <strong>will be reflected<\/strong>.<\/p>\n<h1><span id=\"Summary_ProsCons_of_Each_Method\">Summary (Pros\/Cons of Each Method)<\/span><\/h1>\n<p>Pros\/Cons of each method are as follows.<br>\nUE C++ has a unique description that is not found in regular C++, so you will face with the compilation errors.<br>\nTherefore, we recommend you to create classes by using method (1).<\/p>\n<h3>Method (1) Pros\/Cons of Adding from the UE Editor<\/h3>\n<ul>\n<li>You can only <strong>add<\/strong> C++ files.<\/li>\n<li>Generate minimum <strong>source code<\/strong> automatically. It allows you to start creating classes immediately.<\/li>\n<\/ul>\n<h3>Method (2) Pros\/Cons of Editing on the Explorer<\/h3>\n<ul>\n<li>You can add\/delete\/move\/rename) of C++ files.<\/li>\n<li>You need to write source code from scratch by yourself. You sometime need to copy other source code.<\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This article explains how to add and remove C++ header files and source files (C++ classes) in Unreal Engine.  <\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"templates\/single-home-techblog.php","format":"standard","meta":{"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":false,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[179,154,94,71],"tags":[181],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/colory-games.net\/site\/wp-json\/wp\/v2\/posts\/1134"}],"collection":[{"href":"https:\/\/colory-games.net\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/colory-games.net\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/colory-games.net\/site\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/colory-games.net\/site\/wp-json\/wp\/v2\/comments?post=1134"}],"version-history":[{"count":3,"href":"https:\/\/colory-games.net\/site\/wp-json\/wp\/v2\/posts\/1134\/revisions"}],"predecessor-version":[{"id":1147,"href":"https:\/\/colory-games.net\/site\/wp-json\/wp\/v2\/posts\/1134\/revisions\/1147"}],"wp:attachment":[{"href":"https:\/\/colory-games.net\/site\/wp-json\/wp\/v2\/media?parent=1134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/colory-games.net\/site\/wp-json\/wp\/v2\/categories?post=1134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/colory-games.net\/site\/wp-json\/wp\/v2\/tags?post=1134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}