Announcement

Collapse
No announcement yet.

programming quick start - and compiler doesnt like it

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

  • replied
    Originally posted by MightyMoe2212 View Post
    if someone can explain why it need to be in the .cpp and not in the .h would be nice ^^
    It is a good practice only to include what you use (IWYU) something that UE4 started doing in 4.15. The header file (.h) doesn't need to include ConstructorHelpers.h in order to declare its functions and variables. The implementation file (.cpp) however needs those function declarations to call the function.

    Whenever you change a header file it has to recompile all the classes that uses that header while if you change the implementation file it just has to compile that specific implementation file.

    You can also get multiple definitions with the same name when including it in the header file.
    Last edited by GarnerP57; 10-29-2019, 03:46 PM.

    Leave a comment:


  • replied
    Had the same problem, just add like GarnerP57 said:
    Code:
    #include "RotatingCube.h"
    #include "Components/StaticMeshComponent.h"
    #include "ConstructorHelpers.h"
    in the .cpp file NOT in the .h file!!!

    Edit: Oh if someone can explain why it need to be in the .cpp and not in the .h would be nice ^^
    Last edited by MightyMoe2212; 10-29-2019, 01:52 PM.

    Leave a comment:


  • replied
    Can you show the full header file code for ARotatingCube?

    Leave a comment:


  • replied
    thank you 4 your answers.

    I will try to find a solution to my problems, and if i do, i will post it here. If I dont, I will post again and edit this post here.

    edit: I tried but failed again. This time though there are "only" 3 errors I need your help with.

    In my cpp File :
    -----------------------------------------------------------------------------------
    // Called when the game starts or when spawned
    void ARotatingCube::BeginPlay()
    {
    Super::BeginPlay();

    }
    -----------------------------------------------------------------------------------
    The Word BeginPlay is marked red and it says : "Class UObject" doesnt have a member "BeginPlay".
    As far as I know, if a class inherits members from another one, then we should be able to use its functions. I took a look at the documentation and it said that the class AActor contains the function BeginPlay. But why does the error message mention UObject? didnt our class inherit everything from AActor and with it the things of UObject? The same error message was shown at the following:

    -----------------------------------------------------------------------------------
    // Called every frame
    void ARotatingCube::Tick(float DeltaTime)
    {
    Super::Tick(DeltaTime);
    FVector NewLocation = GetActorLocation();
    FRotator NewRotation = GetActorRotation();
    float RunningTime = GetGameTimeSinceCreation();
    float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime));
    NewLocation.Z += DeltaHeight * 20.0f; //Scale our height by a factor of 20
    float DeltaRotation = DeltaTime * 20.0f; //Rotate by 20 degrees per second
    NewRotation.Yaw += DeltaRotation;
    SetActorLocationAndRotation(NewLocation, NewRotation);
    }
    ------------------------------------------------------------------------------------
    The word "Tick" after the word "Super" is marked red.

    ------------------------------------------------------------------------------------
    UCLASS()
    class MYPROJECT_API ARotatingCube : public AActor
    {
    GENERATED_BODY()

    public:
    // Sets default values for this actor's properties
    ARotatingCube();
    UPROPERTY(VisibleAnywhere)
    UStaticMeshComponent* VisualMesh;
    protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;

    public:
    // Called every frame
    virtual void Tick(float DeltaTime) override;

    };
    ---------------------------------------------------------------------------------------
    the lines above are written in my header file. "GENERATED_BODY()" is marked red and the error message says something about
    considering adding it to a hint file and that this declaration doesnt have a storage class or no type specifier.

    Can someone please help me out here until I have the possibility to learn by myself again using the documentation etc.?

    Last edited by Zodiac Uchiha; 10-08-2019, 05:29 PM.

    Leave a comment:


  • replied
    Go even further than that, there's a really good practice I follow when coding UE C++, and it goes like this:

    1. Use component, say for example UStaticMeshComponent.
    2. Right-click UStaticMeshComponent type and go Quick Actions -> Add Include
    3. Google "unreal engine C++ api UStaticMeshComponent"
    4. Grab the module name from the resulting API page and add it to your build.cs file if it isn't already there.

    If you start getting poorly formatted errors about __cdecl then you did one or more of the following:

    1. Didn't declare the type you're using
    2. Didn't include its header
    3. Didn't add its module.

    I used to forget the module all the time and spend hours ramming my face into the desk trying to work out what was going wrong. It's always one of the above.

    Leave a comment:


  • replied
    The Intellisense has given up tracking down the missing include for UStaticMeshComponent, UStaticMesh and ConstructorHelpers. This code should still compile though since the Actor class that the class inherits from includes those.

    However it is a good practice to explicitly include what you need, and you don't have to worry about including the same thing twice since the
    Code:
    #pragma once
    directive in the header file will ensure that everything is only included once.

    Below
    Code:
    #include RotatingCube.h
    you should add
    Code:
    #include "Components/StaticMeshComponent.h"
    UStaticMesh is within UStaticMeshComponent so you don't have to include that.

    Also add
    Code:
    #include "ConstructorHelpers.h"
    Why is it a good practice to explicitly include things you might ask?

    When you don't explicitly include things you need but expect it to magically be included somewhere else you can end up with having to sort out missing includes in a lot of places if the "magic" include suddenly doesn't exist anymore.

    The order of includes also matters so if something isn't included until after you need it then the build will fail.

    The intellisense has an easier time tracking things and you get rid of the intellisense errors.

    By including it where you need it you avoid these problems.
    Last edited by GarnerP57; 10-08-2019, 07:05 AM.

    Leave a comment:


  • programming quick start - and compiler doesnt like it

    Hi everyone !

    I recently started to learn programming with unreal engine 4 and I encountered a problem :

    I was reading this quick guide :
    https://docs.unrealengine.com/en-US/...art/index.html

    and followed step by step. but i get errors in visual studio. i uploaded a screenshot.
    And here are the error messages i get, and under these the code which is red underlined.


    the classtype pointer-to-incomplete is not permissible
    VisualMesh


    a name followed by :: has to be a class or namespace
    Constructorhelpers


    the identifier "CubeVisualAsset" is not defined
    CubeVisualAsset

    Can someone please help me out here?
    Attached Files
Working...
X