"Introduction to UE4 Programming" Tut Not Working Wit 4.6 ?

Hello mates.

I am new to the UE4 programming. Decided to make a start and got on this one.

https://docs.unrealengine.com/latest/INT/Videos/Player/index.html?series=PLZlv_N0_O1gb5xvsc7VM7pfoRAKLuIcFi&video=ZPn4N3ckP8I

Then I remembered with 4.6 some changes were made. Than followed here to make the necessary changes with cınstructor and pointers.

https://forums.unrealengine.com/showthread.php?53389-4-6-Transition-Guide

But I still get tremendous errors ( around 25) fır just a a .cpp and .h file that include around 20 lines of code or something. Serch around quite a bi but decided to ask it on forums to see if I can get some help.

I just created an Actor from editor just like the tutorial suggested and here is the .cpp and .h files, error log and a screenshot.

Visual Studio 2013, x64.

.h


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "GameFramework/Actor.h"
#include "Pickup.generated.h"


UCLASS()
class TUTORIALCODE_API APickup : public AActor
{
	GENERATED_BODY()

	APickup(const FObjectInitializer& ObjectInitializer);


	/** True when the pickup is available to be picked, faşse if something deactivates the pickup. */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Pickup)
	bool bIsActive;
	

	/**Simple collision component to use as root component*/
	UPROPERTY(VisibleDefaultOnly, BlueprintReadOnly, Category = Pickup)
	USphereComponent* BaseCollisionComponent;

	/**Static mesh to represent the pickup in the level*/
	UPROPERTY(VisibleDefaultOnly, BlueprintReadOnly, Category = Pickup)
	UStaticMeshComponent* PickupMesh;


	/**Function to call when the pickup is collected*/
	UFUNCTION(BlueprintNativeEvent)
	void OnPickedUp();
};


.cpp


// Fill out your copyright notice in the Description page of Project Settings.

#include "TutorialCode.h"
#include "Pickup.h"




APickup::APickup(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{


	/**The ickup is active when ceated*/
	bIsActive = true;

	/**Create the root SphereComponent to handle the pickup's collision*/
	BaseCollisionComponent = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("BaseSphereComponent"));


	/**Set the SphereComponent as the root component*/
	RootComponent = BaseCollisionComponent;

	/**Create static mesh component*/
	PickupMesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("PickupMesh"));

	/**Turn physics on for the statşc mesh*/
	PickupMesh->SetSimulatePhysics(true);

	/**Attach static mesh to root component*/
	PickupMesh->AttachTo(RootComponent);

};

void APickup::OnPickedUp()
{
	/**There is no default behavior for a pickup when it is pickedup*/

};

Error Log:


Error	1	error : In Pickup: BlueprintReadWrite should not be used on private members	C:\UE4\Projects\TutorialCode\Source\TutorialCode\Public\Pickup.h	18	1	TutorialCode
Error	2	error code: OtherCompilationError (2)	C:\UE4\Projects\TutorialCode\Intermediate\ProjectFiles\Error	TutorialCode
Error	3	error MSB3073: The command ""C:\UE4\Epic Games\4.6\Engine\Build\BatchFiles\Build.bat" TutorialCodeEditor Win64 DebugGame "C:\UE4\Projects\TutorialCode\TutorialCode.uproject" -rocket" exited with code -1.	C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets	38	5	TutorialCode
	4	IntelliSense: identifier "FGuid" is undefined	c:\UE4\Epic Games\4.6\Engine\Source\Runtime\Core\Public\Serialization\ArchiveBase.h	561	26	TutorialCode
	5	IntelliSense: identifier "FGuid" is undefined	c:\UE4\Epic Games\4.6\Engine\Source\Runtime\Core\Public\Serialization\ArchiveBase.h	569	18	TutorialCode
	6	IntelliSense: identifier "FGuid" is undefined	c:\UE4\Epic Games\4.6\Engine\Source\Runtime\Core\Public\Serialization\ArchiveBase.h	770	24	TutorialCode
	7	IntelliSense: identifier "FOnSelectedLevelsChangedEvent" is undefined	c:\UE4\Epic Games\4.6\Engine\Source\Runtime\Engine\Classes\Engine\World.h	1976	2	TutorialCode
	8	IntelliSense: identifier "UParticleModuleEventSendToGame" is undefined	c:\UE4\Epic Games\4.6\Engine\Source\Runtime\Engine\Classes\Particles\ParticleSystemComponent.h	890	68	TutorialCode
	9	IntelliSense: identifier "UParticleModuleEventSendToGame" is undefined	c:\UE4\Epic Games\4.6\Engine\Source\Runtime\Engine\Classes\Particles\ParticleSystemComponent.h	903	68	TutorialCode
	10	IntelliSense: identifier "UParticleModuleEventSendToGame" is undefined	c:\UE4\Epic Games\4.6\Engine\Source\Runtime\Engine\Classes\Particles\ParticleSystemComponent.h	921	69	TutorialCode
	11	IntelliSense: identifier "UParticleModuleEventSendToGame" is undefined	c:\UE4\Epic Games\4.6\Engine\Source\Runtime\Engine\Classes\Particles\ParticleSystemComponent.h	933	42	TutorialCode
	12	IntelliSense: no instance of constructor "FReadSurfaceDataFlags::FReadSurfaceDataFlags" matches the argument list	c:\UE4\Epic Games\4.6\Engine\Source\Runtime\Engine\Public\UnrealClient.h	57	92	TutorialCode
	13	IntelliSense: no instance of constructor "FReadSurfaceDataFlags::FReadSurfaceDataFlags" matches the argument list	c:\UE4\Epic Games\4.6\Engine\Source\Runtime\Engine\Public\UnrealClient.h	65	87	TutorialCode
	14	IntelliSense: identifier "FMeshBatchElement" is undefined	c:\UE4\Epic Games\4.6\Engine\Source\Runtime\ShaderCore\Public\VertexFactory.h	488	131	TutorialCode
	15	IntelliSense: cannot open source file "Pickup.generated.h"	c:\UE4\Projects\TutorialCode\Source\TutorialCode\Public\Pickup.h	6	1	TutorialCode
	16	IntelliSense: "Super" is not a nonstatic data member or base class of class "APickup"	c:\UE4\Projects\TutorialCode\Source\TutorialCode\Private\Pickup.cpp	10	3	TutorialCode
	17	IntelliSense: no default constructor exists for class "AActor"	c:\UE4\Projects\TutorialCode\Source\TutorialCode\Private\Pickup.cpp	11	1	TutorialCode


Here is a screenshot. Please notice the Private and Public parts on the left. I dşdn’t create those and in tut video it doesn’t look lşke that. Any ideas ?

thanks in advance for everyone who gives a hand :smiley:

One thing is GENERATED_BODY() defaults to private:. If you want the properties to be public, you have to use a public: identifier.

EDIT: Or use Get() Set() functions.

Sorry couldn’T understand what you meant with that. Can you elaborate a bit ?

Just after the GENERATED_BODY() add public:



...
UCLASS()
class TUTORIALCODE_API APickup : public AActor
{
	GENERATED_BODY()

public:
	APickup(const FObjectInitializer& ObjectInitializer);
...


GENERATED_BODY() defaults to private. Essentially there is a private: identifier at the top of the class. Try adding “public:” (without quotes) right below GENERATED_BODY(). Getters and Setters (GetX() and SetX()) are functions that you implement to be able to access private members. If you wanted to keep the class members private, you would create public functions that could get/set the values of your private members.

Yo mates. I tried what you suggested. But if I am not making a typo not working.

By the way I just noticed my “…generated.h” file can’t be read by the Visual Studio.

I uncheked the “Read Only” in my main build folders’ setting but still… nope.

Man I gotta say. this is a real bummer. After all I was really excited about getting programming with UE4 and just turns out the official tutorials no longer works. Bummy bumming bummer.

There is no generated header because the header tool is choking on your header file. According to the clipped error message in your last screenshot, “Unknown variable specifier VisibleDefaultOnly”. Change that keyword to VisibleDefaultsOnly and see how it goes.

You meant this right ? ( sorry for being a noob) I chnged each one to Defaults

Now I have more errors. Like +4 more.

Does the generated.h file get created, though? If so, that means progress! Instead of the Unreal Header Tool throwing errors, you’re up to the actual C++ compile. That’s a pretty typical thing in C++, more errors does not necessarily mean you’re worse off.

Should it be here ? ( By the way thanks mate, for staying here and helping)

( TutorialCode is the name of the Actor that is created and C:\UE4 is the folder that my engine is located)

I went through this tutorial myself a few days ago. There are a few changes in 4.6 (which I tried to add to the wiki series here).

Here is my header file code, which compiles without any errors in 4.6:

CPP file:

No, since the generated headers are regenerated on the fly and you are not meant to modify them, they are therefore treated as an intermediate file and kept separate.

If the header tool worked properly, it should say so in the build log. And you can reach the file (if it was created) by right clicking the include directive and choosing “Open Document”, I believe.

Ok copy/ pasted your code entirely. Clearly something wrong on my end.

Can you tell me if the place where we get our engine build matters or something ? Or any idea why some people just can not compile their created classes like this ? Anything works at this point really.

Can you post the list of compiler errors you’re getting?

For what it’s worth, I just used the default out of the box version of the engine.

For some reason it started working ???

What daa.

All mates thanks a ton for your efforts.

Maybe we should get this to a sticky or something ? :smiley:

Cheers :smiley:

Hey mate Slayemin . Can ı ask an extra thing.

In the .ccp the last line you added " APickup(const FObjectInitializer& ObjectInitializer); " . So do we have to add thşs şn header files when we create classes ?

Thanks again :smiley:

Yes.

That is the signature for the default constructor for the class. You’ll notice that I define the signature at the bottom of the .H file, and then define the behavior for the constructor in the .CPP file. You pretty much have to create this for every C++ class within UE4. Also note that it’s calling the “super” method in the CPP implementation which passes the input parameter to the base class constructor we’re inheriting from.

Much appreciated.

For those trying to get this to compile on 4.8.1, check out my answer here. https://answers.unrealengine.com/questions/243664/ue4-tutorial-code-transition-issue.html#answer-252059