Download

Fix Bugs In Doc.

Hi all concerned EU4 citizens. I am a new community member and I wanted to try out the programming features of EU4.

I stumbled upon this Official EU4 programming tutorial

of how to create a class in C++ code in UE4.

There are two bugs either in my understanding of basic tutorials. or the tutorial itself.

Sphere1->OnComponentBeginOverlap.AddDynamic(this, &ALightSwitchCodeOnly::OnOverlap); // set up a notification for when this component overlaps something
Sphere1->OnComponentEndOverlap.AddDynamic(this, &ALightSwitchCodeOnly::OnOverlap); // set up a notification for when this component overlaps something

these lines of code do not compile. And no such thing as AddDynamic() functions are visible to me that exists. As a matter of fact __inner_AddDynamic() apparently exists but I dont know how to use it.

Nothing works until I put all the members of the class in the public: zone. I have broke my head over and over until I found how to actually have these components visible in the Editor. No mention or of the public: necessity in the document ofcoarse.

Could the documentation page be updated with current version of coding please? I am in a rather hurry to learn UE4 coding concepts, and I dont want to have these pitfalls spread all over the place.

Can you please post the error that you are getting, as this is still the correct usage even as of 4.5. I am using AddDynamic throughout my game without any issues.

Header code

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

#pragma once

#include “GameFramework/Actor.h”
#include “LightSwitchCodeOnly.generated.h”

/**
*
*/
UCLASS()
class TUTORIALCLASSCREATE_API ALightSwitchCodeOnly : public AActor
{
GENERATED_UCLASS_BODY()

	/** point light component */
	UPROPERTY(VisibleAnywhere, Category = "Switch Components")
	TSubobjectPtr<UPointLightComponent> PointLight1;

/** sphere component */
UPROPERTY(VisibleAnywhere, Category = "Switch Components")
	TSubobjectPtr<USphereComponent> Sphere1;

/** called when something overlaps the sphere component */
UFUNCTION()
	void OnOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

/** the desired intensity for the light */
UPROPERTY(VisibleAnywhere, Category = "Switch Variables")
	float DesiredIntensity;

};

cpp code

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

#include “TutorialClassCreate.h”
#include “LightSwitchCodeOnly.h”

ALightSwitchCodeOnly::ALightSwitchCodeOnly(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
DesiredIntensity = 3000.0f;

PointLight1 = ObjectInitializer.CreateDefaultSubobject<UPointLightComponent>(this, "PointLight1");
PointLight1->Intensity = DesiredIntensity;
PointLight1->bVisible = true;
RootComponent = PointLight1;

Sphere1 = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("Sphere1"));
Sphere1->InitSphereRadius(250.0f);
Sphere1->AttachParent = RootComponent;

Sphere1->OnComponentBeginOverlap.AddDynamic(this, &ALightSwitchCodeOnly::OnOverlap);        // set up a notification for when this component overlaps something
Sphere1->OnComponentEndOverlap.AddDynamic(this, &ALightSwitchCodeOnly::OnOverlap);      // set up a notification for when this component overlaps something

}

void ALightSwitchCodeOnly::OnOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
if (OtherActor && (OtherActor != this) && OtherComp)
{
PointLight1->ToggleVisibility();
}
}

error list

41	IntelliSense: no instance of function template "FComponentBeginOverlapSignature::__Internal_AddDynamic" matches the argument list
        argument types are: (ALightSwitchCodeOnly *, void (ALightSwitchCodeOnly::*)(AActor *OtherActor, UPrimitiveComponent *OtherComp, int32 OtherBodyIndex), FString)
        object type is: FComponentBeginOverlapSignature	c:\Users\ilia\Documents\Unreal Projects\TutorialClassCreate\Source\TutorialClassCreate\LightSwitchCodeOnly.cpp	21	34	TutorialClassCreate

Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Users\ilia\Documents\Unreal Projects\TutorialClassCreate\Source\TutorialClassCreate\LightSwitchCodeOnly.cpp 7 1 TutorialClassCreate

Error 2 error C2143: syntax error : missing ‘,’ before ‘&’ C:\Users\ilia\Documents\Unreal Projects\TutorialClassCreate\Source\TutorialClassCreate\LightSwitchCodeOnly.cpp 7 1 TutorialClassCreate

Error 3 error C2511: ‘ALightSwitchCodeOnly::ALightSwitchCodeOnly(const int)’ : overloaded member function not found in ‘ALightSwitchCodeOnly’ C:\Users\ilia\Documents\Unreal Projects\TutorialClassCreate\Source\TutorialClassCreate\LightSwitchCodeOnly.cpp 8 1 TutorialClassCreate

.
.
.
.
.

there are too many to copy. Basically there are a bunch of things it doesn’t recognize.

Maybe there is Something wrong with ObjectInitializer??? because the template creates something called a PCIP or something like that.

Try changing:


void ALightSwitchCodeOnly::OnOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)

to


void ALightSwitchCodeOnly::OnOverlap( AActor* Other, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult )

And do the same in the header.

Appears the signature did change since the doc was written.

We are aware of the inaccuracies here and plan to have them fixed for the next release.

Thanks for pointing this out!