Hi everyone,
I am relatively new to C++ and working to move certain functionalities out of blueprints. Any help or pointers in the right direction would be highly appreciated!
To start, here are my classes:
UCelestialSkySubsystem // inherits from UEngineSubsystem
UCelestialSkyInterface & ICelestialSkyInterface // cpp interface
ACelestialActorBase // cpp class inheriting from AActor and ICelestialSkyInterface
BP_CelestialBody // abstract BP class inheriting from ACelestialActorBase
BP_Planet // inherits from BP_CelestialBody and implements interface events
I have a function in my subsystem that updates a number, then calls an implemented interface event on each actor in an array of ACelestialActorBase actors—I know these are BP_Planet actors spawned into the world.
The problem is that calling the Execute_Prefix function in my subsystem does not call the implemented event in my BP_Planet actors.
Based on findings in this thread (C++ Interface implemented in BP is null) and the others linked inside it, I know that my BP actors must inherit the interface from a cpp class. I think I have done this properly (see my classes above)—everything compiles, no errors, no crashes, but simply nothing happens when calling Execute_OnElapsedTimeChanged.
I do not have C++ implementations for the interface methods.
The subsystem’s function is SetElapsedTime and the interface method is OnElapsedTimeChanged.
CelestialSkySubsystem.cpp (click to show)
void UCelestialSkySubsystem::SetElapsedTime()
{
// [...set ElapsedTime code...]
// Make an array of values from TMap CelestialBodyActorReferences.
TArray<ACelestialActorBase*> CelestialActors;
CelestialBodyActorReferences.GenerateValueArray(CelestialActors);
// For each CelestialActor, call the OnElapsedTimeChanged interface function.
for (ACelestialActorBase* CelestialActor : CelestialActors)
{
bool bImpl = UKismetSystemLibrary::DoesImplementInterface(CelestialActor, UCelestialSkyInterface::StaticClass());
if (bImpl) // this returns true.
{
ICelestialSkyInterface::Execute_OnElapsedTimeChanged(CelestialActor); // this is the part where nothing happens.
}
}
}
CelestialSkyInterface.h (click to show)
#pragma once
#include "CoreMinimal.h"
#include "CelestialSkyInterface.generated.h"
UINTERFACE()
class UCelestialSkyInterface : public UInterface
{
GENERATED_BODY()
};
class CELESTIALSKY_API ICelestialSkyInterface
{
public:
GENERATED_BODY()
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "CelestialSky|Time")
void OnElapsedTimeChanged();
}
BP_Planet implementation:
The PrintString does not do anything when Execute_OnElapsedTimeChanged is called.
Here is the BP equivalent of what I’m trying to achieve in C++:
This BP equivalent works flawlessly when being used in my editor utility widget, but I am having a great deal of trouble getting this over to C++.
Please help! Thanks again!