Using the sample provided from here:
https://wiki.unrealengine.com/Interfaces_in_C%2B%2B
The provided sample works fine by itself, but if I simply add a “ReactToSunset()” function, this won’t work out with flower.h(or frog.h).
ReactsToTimeOfDay.h – added ReactToSunset()
#pragma once
#include "ReactsToTimeOfDay.generated.h"
/* must have BlueprintType as a specifier to have this interface exposed to blueprints
with this line you can easily add this interface to any blueprint class */
UINTERFACE(BlueprintType)
class MYPROJECT_API UReactsToTimeOfDay : public UInterface
{
GENERATED_UINTERFACE_BODY()
};
class MYPROJECT_API IReactsToTimeOfDay
{
GENERATED_IINTERFACE_BODY()
public:
//classes using this interface MUST implement ReactToHighNoon
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "MyCategory")
bool ReactToHighNoon();
//classes using this interface MUST implement ReactToSunset
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "MyCategory")
bool ReactToSunset();
//classes using this interface MAY implement ReactToMidnight(using blueprint only)
UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "MyCategory")
bool ReactToMidnight();
};
ReactsToTimeOfDay.cpp – Unchanged
// Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.
#include "MyProject.h"
#include "ReactsToTimeOfDay.h"
UReactsToTimeOfDay::UReactsToTimeOfDay(const class FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}
Flower.h – added ReactToSunset() and ReactToSunset_Implementation()
//..other includes may appear here depending on your class
#include "ReactsToTimeOfDay.h"
#include "ASkeletalMeshActor.generated.h"
UCLASS()
class AFlower : public ASkeletalMeshActor, public IReactsToTimeOfDay
{
GENERATED_BODY()
public:
/*
... other AFlower properties and functions declared ...
*/
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "MyCategory")
bool ReactToHighNoon();
virtual bool ReactToHighNoon_Implementation() override;
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "MyCategory")
bool ReactToSunset();
virtual bool ReactToSunset_Implementation() override;
};
Flower.cpp – added ReactToSunset_Implementation()
//other flower.cpp code
bool AFlower::ReactToHighNoon_Implementation()
{
//Default behaviour for how flower would react at noon
//OpenPetals();
//AcceptBugs();
//...
return true;
}
bool AFlower::ReactToSunset_Implementation()
{
//Default behaviour for how flower would react at sunset
//DoStuf()
//...
return true;
}
I get this error message in VS:
I tried to come out with different signature for ReactToHighNoon and ReactToSunset(with a different return value type and different number of parameters), butI still get the exact same messsage error.
What’s going on?
(Note: I’m using Unreal 4.15.3)