Announcement

Collapse
No announcement yet.

Is there a 4.22 C++ guide best practices somewhere?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Is there a 4.22 C++ guide best practices somewhere?

    Hi all. I'm going through a tutorial up on Pluralsight's website. It's C++ and Blueprints. The video series was done a couple years ago. Even when I follow his instructions step by step I'm getting lots of errors. I think it's probably a combination of him using an older version of both UE4 and older VS. I'm running UE4.22 and VS2019.

    Some of the problems I'm experiencing is the compiler not finding header files with Paper2D. I had to manually go enter in the path to the header file. But, even after that, I got compile errors with .generated. files.

    I'm extremely new to UE development, however, I've been writing software for many-a-moon. . Having said that, my primary language has been C# and my C++ is pretty crusty. But hey. I'll dust it off.

    So, yeah, I was hoping to find out if there is a doc that really shows the best practices for setting up VS and C++ to help rid of compile errors dealing with paths and what not.

    Thanks!!!

    Rick

    #2
    I am in the process of writing a decent guide for setting up QT Creator for the Engine in Linux. But the basic methodology is invariant of the platform. What you have to recognize is existence two very important files
    1. UnrealBuildTool (present in Engine/Binaries/DotNet/)
    2. UnrealHeaderTool (present in Engine/Binaries/WhateverPlatformYouAreUsing/)
    These files are the essence of any Unreal Engine project, beginning from generating IDE specific files and compiling/debugging the code on platform. For their commandline parameters, read the platform specific scripts (or look into the source). Good luck!
    https://ravimohan.net/
    https://github.com/ravimohan1991

    Comment


      #3
      Originally posted by The-Cowboy View Post
      I am in the process of writing a decent guide for setting up QT Creator for the Engine in Linux.
      When you're done with that, you can write one for Windows/Visual Studio.


      Comment


        #4
        Let us just say that writing about proprietary software is not my "cup of coffee"!
        https://ravimohan.net/
        https://github.com/ravimohan1991

        Comment


          #5
          The ".generated.h" file needs to be the last include file, anything else you include should happen before that. I'm not sure what other help I can give without seeing the build errors.

          Comment


            #6
            Originally posted by nilamo View Post
            The ".generated.h" file needs to be the last include file,
            Why is so? And what is the utility of ".generated.h" files?
            https://ravimohan.net/
            https://github.com/ravimohan1991

            Comment


              #7
              Originally posted by The-Cowboy View Post
              Why is so? And what is the utility of ".generated.h" files?
              Open one up and look (after you compile a class successfully). It's all the Blueprint / Replication / UProperty / UFunction glue that is generated by the UnrealHeaderTool.
              Able Ability System - A high performance, robust ability system for UE4. Now Available!

              Comment


                #8
                Could you be more specific about the glue part? For instance the Party.generated.h looks like
                Code:
                // Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
                /*===========================================================================
                    Generated code exported from UnrealHeaderTool.
                    DO NOT modify this manually! Edit the corresponding .h files instead!
                ===========================================================================*/
                
                #include "UObject/ObjectMacros.h"
                #include "UObject/ScriptMacros.h"
                
                PRAGMA_DISABLE_DEPRECATION_WARNINGS
                #ifdef UNREALTOURNAMENT_Party_generated_h
                #error "Party.generated.h already included, missing '#pragma once' in Party.h"
                #endif
                #define UNREALTOURNAMENT_Party_generated_h
                
                #define UnrealTournament_Source_UnrealTournament_Public_Online_Party_h_116_RPC_WRAPPERS
                #define UnrealTournament_Source_UnrealTournament_Public_Online_Party_h_116_RPC_WRAPPERS_NO_PURE_DECLS
                #define UnrealTournament_Source_UnrealTournament_Public_Online_Party_h_116_INCLASS_NO_PURE_DECLS \
                private: \
                    static void StaticRegisterNativesUParty(); \
                    friend struct Z_Construct_UClass_UParty_Statics; \
                public: \
                    DECLARE_CLASS(UParty, UObject, COMPILED_IN_FLAGS(0 | CLASS_Config), CASTCLASS_None, TEXT("/Script/UnrealTournament"), NO_API) \
                    DECLARE_SERIALIZER(UParty) \
                    static const TCHAR* StaticConfigName() {return TEXT("Game");}
                 ....
                
                PRAGMA_ENABLE_DEPRECATION_WARNINGS
                In other words, what new structure is provided by this file that cannot be achieved by traditional C++ compilation process (which don't involve .generated.h). On the local scale I understand that it supports the error spitting mechanism and all that, but what exactly does it stand for on global scale?
                https://ravimohan.net/
                https://github.com/ravimohan1991

                Comment


                  #9
                  I don't know the specifics but I do know that I've been watching video tutorials and they have said the same thing. Nothing below the .generated. file.

                  Comment


                    #10
                    There's more in there for more complicated things, like Replicated variables or Blueprint callable functions. For an empty class, it should basically be nothing except reflection info.

                    Comment


                      #11
                      Ok, I should take that for face value I guess. Things get even more weird. Has anyone noticed the thing about white spaces? For instance the practice of writing
                      Code:
                      #pragma once
                      
                      #include "UTWeaponAttachment.h"
                      
                      #include "UTWeapAttachment_ImpactHammer.generated.h"
                      is good, but the same code, without spaces as follows
                      Code:
                      #pragma once
                      
                      #include "UTWeaponAttachment.h"
                      #include "UTWeapAttachment_ImpactHammer.generated.h"
                      is spitting out errors. Testing with QT Creator.
                      Last edited by The-Cowboy; 06-04-2019, 08:15 PM.
                      https://ravimohan.net/
                      https://github.com/ravimohan1991

                      Comment


                        #12
                        Can you share the errors? Because code-wise that should be the same, however know that UE4 has a feature called Unity Build (not to be confused with Unity engine) that combines source files before compiling. That reduces compilation times for larger projects, but it there are two things to be aware of:
                        * You never know which files are going to be combined before compiling, small changes (such as a space) may cause files to be combined in a different way
                        * The files being combined will often mask the fact that some of your code is missing includes.

                        For example if a source file of yours is using the class MyClass and it's not being included, that's an error in your code right? But unity build may be combining that file with another file that does include MyClass.h and your project will build fine, unless some small changes causes files to be combined in a different way and the error surfaces.

                        That's the only explanation that I can think of for why a newline is the difference between error and no error for you.
                        Journeyman's Minimap - Available on Marketplace - Forum topic - Video

                        Comment


                          #13
                          Hi Zhi, thanks for the interest. I will post the error in the next cycle of building process (the project is too global and the error spits are overwhelming!).
                          https://ravimohan.net/
                          https://github.com/ravimohan1991

                          Comment


                            #14
                            Ok equivalent problem. In UTGameState.h the following directives are fine
                            Code:
                            #pragma once
                            
                            #include "UTPlayerState.h"
                            #include "UTCharacter.h"
                            #include "ChartCreation.h"
                            
                            #include "UTGameState.generated.h"
                            but when I include
                            Code:
                            #include "UTLineUpZone.h"
                            QT Creator spits the error in UTGameState.cpp
                            Code:
                            incomplete type 'AUTGameState'  in nested name specifier
                            in front of all the member functions defined.
                            I tried all possible permutations in the list but of no avail. Curiously it doesn't even matter if I comment out the last directive, it is as if it is counting the number of lines.

                            Finally the code
                            Code:
                            #pragma once
                            
                            #include "UTPlayerState.h"
                            #include "UTCharacter.h"
                            #include "ChartCreation.h"
                            #include "UTLineUpZone.h"
                            #include "UTGameState.generated.h"
                            without white space in the last pair works.
                            Last edited by The-Cowboy; 06-06-2019, 10:37 AM.
                            https://ravimohan.net/
                            https://github.com/ravimohan1991

                            Comment


                              #15
                              Few things that may help:

                              1. In the .h files you usually don't need to have other header includes. If you're using other classes you can use 'class' in front to forward declare it.
                              Ex:
                              Code:
                              UPROPERTY() class AUTGameState* GameState;
                              That will compile fine, and will only need the header when used in the .cpp file, not in the .h file. This may clear up issues with things referencing each other in headers which is what it seems like that 'nested' error is.

                              2. If you ever try using something like FTableRowBase and notice bogus linkage or 'not found' errors, google it and the page will show the following:
                              - Which header to include in the .cpp
                              - Which module name to add to your publicdependencies in ProjectName.Build.cs

                              3. Cached problems! Somethings things just don't work even though they should. Usually worth doing a full rebuild of the project, or deleting the intermediate folder, regenerating project files (right click the .uproject file) and rebuilding the game.
                              This could fix odd compiler/game errors that just don't make sense (possibly the spacing errors).

                              Comment

                              Working...
                              X