Components.Add and OnComponent*Overlap.AddDynamic

Unfortunately, going through the very first C++ bits in the docs, I’m encountering something I don’t understand.

Code and Blueprint Docs

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

#include "BasicClasses.h"
#include "LightSwitchBoth.h"

ALightSwitchBoth::ALightSwitchBoth(const class FPostConstructInitializeProperties& PCIP)
    : Super(PCIP) {

    DesiredBrightness = 15.0f;

    PointLight1 = PCIP.CreateDefaultSubobject<UPointLightComponent>(this, "PointLight1");
    PointLight1->Brightness = DesiredBrightness;
    PointLight1->bVisible = true;
    RootComponent = PointLight1;
    Components.Add(PointLight1);

    Sphere1 = PCIP.CreateDefaultSubobject<USphereComponent>(this, TEXT("Sphere1"));
    Sphere1->InitSphereRadius(250.0f);
    Sphere1->OnComponentBeginOverlap.AddDynamic(this, &ALightSwitchBoth::OnOverlap);        // set up a notification for when this component overlaps something
    Sphere1->OnComponentEndOverlap.AddDynamic(this, &ALightSwitchBoth::OnOverlap);      // set up a notification for when this component overlaps something
    Sphere1->AttachParent = RootComponent;
    Components.Add(Sphere1); }
  1. Components doesn’t exist. There’s an API AddComponent AActor::AddComponent(FName TemplateName, bool bManualAttachment, const FTransform& RelativeTransform, const UObject* ComponentTemplateContext) but I’m not clear that it does the same thing.
  2. AddDynamic is marked __internal

Are there equivalent APIs or am I just reading something wrong?

Yes, I’m aware this is very simple in blueprint, but I’m trying to crack the c++ side as a learning exercise.

The API has changed recently, you no longer need to add the components explicitly when creating them in the constructor. For further details see this forum post. I don’t have an answer for the second part of your question though.

Thanks, I found that forum post about 45 seconds ago :wink:

Second half of the answer = AddDynamic is a macro, so that was the issue. Intellisense stops complaining after you compile.