I do not really understand what the issue you are trying to solve. What is stopping you from
make some simpler pieces of virtual
equipment in Blueprint
with BueprintCallable functions? As i understand, you do not need to change the functionality of the function itself, just call it on instances you want to implement with BP.
What you can also look into, is this:
BlueprintNativeEvent is for situations where you provide default C++ implementation but give opportunity to override it in Blueprints.
Maybe this will help to set you on the right track?
If not, could you please elaborate on what you would like to achieve and where is the problem and we’ll try to help you.
I’m working on a virtual tv studio, and I have an interface with the functions AddOutput, RemoveOutput, and GetRenderTarget implemented in C++ so the different bits of virtual equipment can talk to each other. I also have a camera using a USceneCaptureComponent2D setup in C++. The issue is, when I try to call any of the camera’s functions through the interface in Blueprint, it either complains that it isn’t marked as BlueprintCallable, or just doesn’t run. When I try to mark it as blueprint callable in my TVCamera.h file, it doesn’t let me compile, because I didn’t mark it as BlueprintImplementable like it is in the interface. When I mark it as BlueprintImplementable, it won’t compile because i’ve implemented it in C++. I need the interface to be BlueprintImplementable because I plan to make some simpler pieces of virtual equipment in Blueprint. What should I do?
TVCamera.h:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "TVVideoInterface.h"
#include "Engine/TextureRenderTarget2D.h"
#include "TVCamera.generated.h"
class USceneCaptureComponent2D;
UCLASS()
class TVSYSTEM_API ATVCamera : public AActor, public ITVVideoInterface
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ATVCamera();
// Functions
UFUNCTION(BlueprintCallable, Category = "Video")
UTextureRenderTarget2D* AddOutput();
UFUNCTION(BlueprintCallable, Category = "Video")
bool RemoveOutput();
UFUNCTION(BlueprintCallable, Category = "Video")
UTextureRenderTarget2D* GetRenderTarget() const;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Components
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Camera")
USceneCaptureComponent2D* SceneCaptureComp;
// Properties
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
int ResolutionX;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
int ResolutionY;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
TEnumAsByte<ETextureRenderTargetFormat> RenderTargetFormat;
UTextureRenderTarget2D* RenderTarget;
// The amount of users using this camera
int Users;
// Functions
void UpdateIsRendering();
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};
TVVideoInterface.h:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "TVVideoInterface.generated.h"
class UTextureRenderTarget2D;
// This class does not need to be modified.
UINTERFACE(Blueprintable)
class UTVVideoInterface : public UInterface
{
GENERATED_BODY()
};
/**
*
*/
class TVSYSTEM_API ITVVideoInterface
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
/* Add an output to this camera. Returns the RenderTarget for this source. */
UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "Video")
UTextureRenderTarget2D* AddOutput();
/* Remove an output from this source. If there are zero outputs on a camera, it will stop rendering. */
UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "Video")
bool RemoveOutput();
/* Gets a reference to the render target of the source. Do not use for output adding. */
UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "Video")
UTextureRenderTarget2D* GetRenderTarget();
};
What I’m saying is it’s not letting me mark the function in the camera class as UFUNCTION because then it wouldn’t mach the definition in the interface, and the interface has to be marked as Blueprint Implementable so I can use it in Blueprint. The one in the camera class can’t be Blueprint Implementable because I implement in in c++
Events need C++ code in order to forward call in to Blueprint, thats why BlueprintImplementableEvent is generating definition of function and you can not redefine it. There is other option called BlueprintNativeEvent it works the same just it also define function in C++ but with _Implementation suffix in function name, which is called when blueprint don’t override the event.
Ok, I understand that you want to implement an interface call in C++? The syntax you use is not correct. Check out these links, maybe it will help:
But to me, if it is not a neccessity to implement interface in C++ (for whatever reason), implementing Interface call in BP is easier, at least at first. After you create BP based on C++ class, in class settings of your BP you can choose Interface it implements, then you will have your Interface events in BP, and can implement functionality.
And how exactly do you implement the “_Implementation” without getting an error, because it’s already defined?
… in the base-“class”, I mean, as a default implementation. It doesn’t even have to be virtual at all… just call virtual member functions from code.