I have an actorcomponent UEventPublisher, and I’m trying to create it in the root AActor’s constructor and take care of registering it automatically, so the component can tick and such without any extra work:
Hmm, there’s still an error from line 4 (from your paste), “ObjectInitializer: undeclared identifier”. I got the same error before when I was searching online and trying different people’s implementations- am I missing an #include maybe? I have CodeProject.h and CodeProjectCharacter.h in the cpp, and GameFramework/Character.h, EventPublisher.h, and CodeProjectCharacter.generated.h in my .h file.
Oh, I found what you mean. It included EngineMinimal.h already, I altered it to also include Engine.h with no results… it is so weird to me that ObjectInitializer is reading undefined, just to confirm, this is correct, right?
CodeProjectCharacter.h:
class ACodeProjectCharacter : public ACharacter
{
GENERATED_BODY()
/** Camera boom positioning the camera behind the character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class USpringArmComponent* CameraBoom;
/** Follow camera */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class UCameraComponent* FollowCamera;
public:
ACodeProjectCharacter();
ACodeProjectCharacter(const FObjectInitializer& ObjectInitializer);
CodeProjectCharacter.cpp:
ACodeProjectCharacter::ACodeProjectCharacter()
{
// Set size for collision capsule
GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);
EventPublisher = ObjectInitializer.CreateDefaultSubobject<UEventPublisher>(this, TEXT("EventObj"));
Just adding this to clarify, I can mouseover ObjectInitializer in the .h, and the popup correctly identifies it as “const FObjectinitializer &ObjectInitializer”, so I know it’s getting typed correctly, but cutting & pasting “ObjectInitializer” from that line to the .cpp still returns the unknown type error.
Same undeclared identifier error on ObjectInitializer- what’s weirding me out is that this is a brand-new project, the only change to the base state was creating EventPublisher, and that doesn’t interact with anything.
CodeProjectCharacter.h has an #include for EventPublisher.h, and I declare it in the character’s header.
Sure, here’s the class constructor in the .cpp the error is listing. The exact error is "Error MyFilePath\CodeProject\Source\CodeProject\CodeProjectCharacter.cpp(16) : error C2065: ‘ObjectInitializer’ : undeclared identifier
"
The listed line, 16, is the one that starts “EventPublisher = ObjectInitializer.CreateDefaultSubobject”