Hello. I am pretty new to the C++ side of Unreal, but I’ve been trying hard to learn it.
I have an Nvidia WaveWorks build integrated into my UE4, and have been trying to adjust the source code to work more for what I am trying to accomplish. By default WaveWorks buoyancy works with static meshes, but not actors or blueprints that have static mesh components. I have a boat actor that houses a static mesh and a function to return that static mesh.
I have been attempting to access the uStaticMeshComponent of my boat inside of the WaveWorksFloatingComponent.cpp in order to pass it into the BuoyancyBodyComponent and calculate its buoyancy. I created a function with an object iterator in the WaveWorksFloatingComponent that is supposed to access the function that returns the uStaticMeshComponent. I thought I had maybe finally figured out the correct solution because everything compiles successfully, but unfortunately crashes without log when trying to play or simulate. I am thinking my logic with object iterator might be off as I don’t 100% understand it.
Any help, whether its logic fixing or troubleshooting, is greatly appreciated. Thank you.
This is my boat actor and its components. (MyActor.cpp)
AMyActor::AMyActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
RootComponent = Root;
Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
Mesh->AttachTo(Root);
}
UStaticMeshComponent* AMyActor::GetSM()
{
return Mesh;
}
Here are functions and properties in header (MyActor.h)
UPROPERTY()
USceneComponent* Root;
UPROPERTY(EditAnywhere)
UStaticMeshComponent* Mesh;
UFUNCTION()
UStaticMeshComponent* GetSM();
This is function I am using to try to access GetSM() from MyActor. (WaveWorksFloatingComponent.cpp)
void UWaveWorksFloatingComponent::AccessFunction()
{
for (TObjectIterator<AMyActor> Itr; Itr; ++Itr)
{
if (Itr->IsA(AMyActor::StaticClass()))
{
AMyActor* actorClass = *Itr;
actorClass->GetSM();
}
}
}
Here is where I am using that function. The commented out section was the original code. (WaveWorksFloatingComponent.cpp)
if (nullptr != WaveWorksActor)
{
WaveWorksComponent = Cast<UWaveWorksComponent>(WaveWorksActor->GetComponentByClass(UWaveWorksComponent::StaticClass()));
WaveWorksStaticMeshComponent = Cast<UWaveWorksStaticMeshComponent>(WaveWorksActor->GetComponentByClass(UWaveWorksStaticMeshComponent::StaticClass()));
WaveWorksRecieveDisplacementDelegate = FWaveWorksSampleDisplacementsDelegate::CreateUObject(this, &UWaveWorksFloatingComponent::OnRecievedWaveWorksDisplacements);
AccessFunction();
BuoyancyBodyComponent = Mesh;
//BuoyancyBodyComponent = Cast<UStaticMeshComponent>(GetOwner()->GetComponentByClass(UStaticMeshComponent::StaticClass()));
And here is the AccessFunction() in header. (WaveWorksFloatingComponent.h)
UFUNCTION()
void AccessFunction();
And the variables in header. (WaveWorksFloatingComponent.h)
class UStaticMeshComponent* BuoyancyBodyComponent;
class UStaticMeshComponent* Mesh;
I am 99% sure the problem is isolated in the above code, but if you think I am leaving a relevant code snippet out please tell me. Again, any help is greatly appreciated. Thank you.
edit1: left out variables for WWFC header.