Could I get some help with a small syntax problem?

So I’m not at all familiar with C++ or UE4 in general, so I imagine this really isn’t difficult to fix, but I’m having a little trouble. I’m following this (A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums) tutorial to try and achieve the ‘true first person’ view for the player. It’s been fine up to the ‘YourCharacter.h’ tab. I’m not sure of the syntax for global variables, and when I just paste

public:
    virtual FRotator GetViewRotation() const OVERRIDE;

in, I get the following errors when I try to compile and run:

Any help is greatly appreciated!
Thanks very much.

You have no class definition (should be created for you automatically when you add code through the editor).

To me this indicates that you have no familiarity with C based languages at all - C++ is powerful, but will give you a lot of opportunity to really break things and cause yourself a lot of frustration whilst not getting anywhere. I would very strongly recommend at least picking up a book covering the basics and working through it if you intend to start programming and want to achieve anything.

I have a copy of the first edition of this book and it is quite reasonable:

UCLASS()
class ATrueFirstPerson : ACharacter
{

       GENERATED_UCLASS_BODY()

public:
      virtual FRotator GetViewRotation() const OVERRIDE;
 
}

…to be more exact, without UHT macros class won’t be visible for the rest of the engine code.

Best way to make class is use “Add Code To Project” in editor, it will setup everything you need

You need to create a class like this:

class ATrueFirstPerson : ACharacter
{

public:
      virtual FRotator GetViewRotation() const OVERRIDE;

}

I am not sure how you created your class, but the structure of your header file is wrong. When you create a new class, the code in your header file should look something like this:

// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.

#pragma once

#include "GameFramework/Character.h"
#include "MyOculusCharacter.generated.h"

/**
 * 
 */
UCLASS()
class TESTOCULUSSETUP_API AMyOculusCharacter : public ACharacter
{
	GENERATED_UCLASS_BODY()

	
	
};

You would then paste the lines from the tutorial in like this:

// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.

#pragma once

#include "GameFramework/Character.h"
#include "MyOculusCharacter.generated.h"

/**
 * 
 */
UCLASS()
class TESTOCULUSSETUP_API AMyOculusCharacter : public ACharacter
{
	GENERATED_UCLASS_BODY()

public:
	virtual FRotator GetViewRotation() const OVERRIDE;
	
};

As ambershee mentioned, C++ is very powerful, but it also assumes you have a very good idea of what you are doing. It is not very forgiving. If you are not familiar with C++, I would recommend starting with something simple and building on that. It doesn’t take long to learn C++, but it will take years to master it.

Edit For clarification, some parts of this structure are unique to Unreal Engine 4. Creating a standard C++ class will not work for you in this case. However, if you create a class through the Editor by using File → Add Code to Project, you will be presented with a class creation “wizard” that will provide you with a .h and .cpp file for a new class that already has the basic structure needed to create a new class in UE4.

oops, I completely forgot about the macros. :stuck_out_tongue:

I’m familiar with C, nothing to this extent though. Kinda sucks that my university doesn’t really cover anything that in-depth, just glazes over and teaches the theory behind it. I guess it couldn’t hurt at all to pick it up and learn.

Thanks for the advise!

I’ve updated the OP in the hopes someone can assist me. Thanks to those who posted!

The error is exactly what it says on the tin:
“GetViewRotation: Can’t override a ‘final’ function”

GetViewRotation is declared as final, which means it cannot be overridden.

I couldn’t help but notice that your output has the -rocket command switch in it, which I’m assuming you’re also copying from the tutorial. Rocket as the internal codename for the public UE4 build long before it became public - I suspect the tutorial you are following is potentially very out of date…

Ah ■■■■, that’s a shame. Well, I’ll focus on other stuff until something similar arises then. Thanks for the help!

Hi Beechey,

We prefer to keep a record of all questions on the AnswerHub, and any solutions that are provided, so that future users can easily find help if they run into an issue that someone else already struggled with. If you have multiple or additional questions, it is requested that you post a new question for each one. I will be reverting this post back to your original question. Please feel free to create a new post for your additional questions so we can track those separately.

Thanks,
Tim

Ah, fair enough, Tim. Is there any way we can close this or do you prefer to leave threads open? The issue is sorted anyway - silly me not reading instructions. I know better next time!

Hi Beechey,

We will typically leave a post open unless the discussion goes way off topic, or someone resurrects a really old post by adding a new question to it. This way, if someone else has another solution to the same issue that they would like to add, or needs to ask for clarification about something, they can easily do so.

If one of the answers that is given to a question you post helps resolve the issue you are having, or points you in the right direction for resolving it, make sure to select that answer as correct and/or leave a comment under it indicating what additional steps you took to make that answer work for you.

Have a great day!