So i have two or more actors, one called “Commander” with the component “TickPulse”, the other components (let’s call them “cells”) will contain a component “CellControls”. “Commander” will be used to send out broadcasts with an array that contain things that the cells can then work on and keep all cells in sync.
TickPulse.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "TimerPulse.h"
#include "Runtime/Engine/Public/TimerManager.h"
// Sets default values for this component's properties
UTimerPulse::UTimerPulse()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
// ...
}
void UTimerPulse::TimerLoop()
{
UE_LOG(LogTemp, Warning, TEXT("pulse bop bop"));
TArray<int> test = {1,2,3,4,5};
TickPulse.Broadcast(test);
//TickPulse.Broadcast();
}
// Called when the game starts
void UTimerPulse::BeginPlay()
{
Super::BeginPlay();
// ...
// UWorld
UWorld* World = ();
// Setting up the timer
World->()->GetTimerManager().SetTimer(TimerPulseHandle, this, &UTimerPulse::TimerLoop, TimerDelayTime, true, 1.f);
}
// Called every frame
void UTimerPulse::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
}
TickPulse.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Engine/Engine.h"
#include "Runtime/Engine/Public/TimerManager.h"
#include "TimerPulse.generated.h"
// Part of delegate
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSendPulse, TArray<int>, map);
//DECLARE_DYNAMIC_MULTICAST_DELEGATE(FSendPulse);
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class ALEVEL_API UTimerPulse : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UTimerPulse();
// Part of delegate
UPROPERTY(BlueprintAssignable)
FSendPulse TickPulse;
// Timer
void TimerLoop();
float TimerDelayTime = 1.f;
FTimerHandle TimerPulseHandle;
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
};
CellControl.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "CellControl.h"
#include "TimerPulse.h"
#include "Kismet/GameplayStatics.h"
// Sets default values for this component's properties
UCellControl::UCellControl()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
// ...
}
//Super::PostInitializeComponents();
// Receive from delegate event dispatcher
void UCellControl::Recevier(TArray<int> test)
{
//AActor Sender = Null;
//ACharacter* Sender = UGameplayStatics::GetPlayerChracter((), 0);
Sender->TickPulse.AddDynamic(this, UCellControl::CellDoSomething(test));
}
void UCellControl::FindSender()
{
// Getting the adress of the sender
for (TActorIterator<AActor> ActorItr(()); ActorItr; ++ActorItr)
{
// Same as with the Object Iterator, access the subclass instance with the * or -> operators.
AActor* ActorI = *ActorItr;
UE_LOG(LogTemp, Warning, TEXT("Actor: %s"), *ActorI->GetFName().ToString())
if (ActorI->GetFName().ToString().Contains(TEXT("Commander")))
{
Sender = ActorI;
break;
}
//ClientMessage(ActorItr->GetActorLocation().ToString());
}
}
void UCellControl::CellDoSomething(TArray<int> input_int)
{
UE_LOG(LogTemp, Warning, TEXT("Cell doing something"));
}
/*
void UCellControl::CellDoSomething()
{
UE_LOG(LogTemp, Warning, TEXT("Cell doing something"));
}
*/
// Called when the game starts
void UCellControl::BeginPlay()
{
Super::BeginPlay();
FindSender();
}
// Called every frame
void UCellControl::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
}
CellControl.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "TimerPulse.h"
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "GameFramework/Actor.h"
#include "Kismet/GameplayStatics.h"
#include "EngineUtils.h"
#include "CellControl.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class ALEVEL_API UCellControl : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UCellControl();
// Part of delegate
virtual void PostInitializeComponents();
UFUNCTION()
void Recevier(TArray<int> test);
AActor* Sender;
void FindSender();
protected:
// Called when the game starts
virtual void BeginPlay() override;
// Cell Control
UFUNCTION()
//void CellDoSomething();
void CellDoSomething(TArray<int> input_int);
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
};
So the above are the codes and the error I am receiving from the editor is CellControl.cpp (26): error C2039: 'TickPulse': is not a member of AActor
I am wondering if this would be because the actor iterator only works when the game is running?
(ps. there might also be other bugs or errors but the unreal editor seems to be fine with them for now, not too sure)