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

  • replied
    Originally posted by The-Cowboy View Post
    Could you be more specific about the glue part? For instance the Party.generated.h looks like
    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?
    Just a sound reference for the utility of ".generated.h" files the way I wanted https://answers.unrealengine.com/que...ml?sort=oldest

    Leave a comment:


  • replied
    Originally posted by Juice-Tin View Post
    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.
    But that occurs in the .cpp file.

    Originally posted by Juice-Tin View Post
    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).
    Maybe I wasn't clear enough. The error is detected by QT Creator as per the presence/absence of certain white spaces. That is weird and mysterious.

    Leave a comment:


  • replied
    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).

    Leave a comment:


  • replied
    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.

    Leave a comment:


  • replied
    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!).

    Leave a comment:


  • replied
    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.

    Leave a comment:


  • replied
    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.

    Leave a comment:


  • replied
    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.

    Leave a comment:


  • replied
    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.

    Leave a comment:


  • replied
    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?

    Leave a comment:


  • replied
    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.

    Leave a comment:


  • replied
    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?

    Leave a comment:


  • replied
    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.

    Leave a comment:


  • replied
    Let us just say that writing about proprietary software is not my "cup of coffee"!

    Leave a comment:

Working...
X