Are you creating classes in visual studio just by adding new classes or UE4 editor to add code to project?
Header:
// Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "UDanceInterface.generated.h"
/** Class needed to support InterfaceCast<IToStringInterface>(Object) */
UINTERFACE(MinimalAPI)
class UDanceInterface : public UInterface
{
GENERATED_UINTERFACE_BODY()
};
class IDanceInterface
{
GENERATED_IINTERFACE_BODY()
virtual FString ToString();
};
cpp:
#include "DanceInterface.h"
//////////////////////////////////////////////////////////////////////////
// ToStringInterface
UDanceInterface::UDanceInterface(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
}
//This is required for compiling, would also let you know if somehow you called
//the base event/function rather than the over-rided version
FString IDanceInterface::ToString()
{
return "IDanceInterface::ToString()";
}
And something that uses interface
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "DanceCharacter.h"
#include "DanceInterface.h"
#include "DanceBot.generated.h"
/**
*
*/
UCLASS()
class ADanceBot : public ADanceCharacter, public IDanceInterface
{
GENERATED_UCLASS_BODY()
public:
virtual FString ToString() OVERRIDE;
};
cpp:
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
#include "Dance.h"
#include "DanceBot.h"
ADanceBot::ADanceBot(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
}
//IToStringInterface
FString ADanceBot::ToString()
{
return "DanceBot!";
}
Ok It compiles! But still this generated thing is confusing. Some basic classes can be generated from editor but can’t do the same for interface… ?