Download

Actor Component will not tick

Hi all,

Having a very unusual problem where one of my components will not tick. It only happens for this one component, and I seem to have set it up the same way as my others.

Any help would be greatly appreciated, it’s a real head-scratcher:

Header:


UCLASS(meta = (BlueprintSpawnableComponent))
class ROGUELIKE_API UDamageZone : public USphereComponent
{
	GENERATED_UCLASS_BODY()

public:
	//The interval by which to apply damage
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = DamageZone)
	float Interval;

	UFUNCTION()
	void OnBeginOverlap(class UPrimitiveComponent* HitComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
	UFUNCTION()
	void OnEndOverlap(class UPrimitiveComponent* HitComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

	void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;

private:
	float timeSinceLastTick;
};

Body:



#include "DamageZone.h"

UDamageZone::UDamageZone(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
	OnComponentBeginOverlap.AddDynamic(this, &UDamageZone::OnBeginOverlap);
	OnComponentEndOverlap.AddDynamic(this, &UDamageZone::OnEndOverlap);

	this->SetComponentTickEnabled(true);
}

void UDamageZone::OnBeginOverlap(class UPrimitiveComponent* HitComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
       //logic to add character to collection of overlapped characters
}

void UDamageZone::OnEndOverlap(class UPrimitiveComponent* HitComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
       //logic to remove character to collection of overlapped characters
}

void UDamageZone::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
	timeSinceLastTick += DeltaTime;
        //logic to deal damage
}

I’ve removed a lot of the specific implementation logic as it’s irrelevant and didn’t want to spam too much code. This component is attached to an actor made using the blueprint system. The overlaps both work and I can hit breakpoints within them, but the tick function is never called.

I’ve tried calling various functions in the constructor to enable the tick, including the one shown, and none work. I can’t remember the names of the others off the top of my head.

Any help would be greatly appreciated

Remove this from the constructor:



this->SetComponentTickEnabled(true);


And add this:



PrimaryComponentTick.bCanEverTick = true;
PrimaryComponentTick.bStartWithTickEnabled = true;


Ok I have spent so many real “ticks” (120 minutes to be precise) to figure this. I tried all the permutations of



    PrimaryComponentTick.bCanEverTick = true;
    RegisterAllComponentTickFunctions(true);
    PrimaryComponentTick.bStartWithTickEnabled = true;
    this->SetComponentTickEnabled(true);
    bTickInEditor = true;


nothing works. What more, when I include



RegisterComponentTickFunctions(true);


Engine crashes with the error spit



LoginId:noiwillnottellyou
EpicAccountId:

Assertion failed: GTestRegisterComponentTickFunctions == __null [File:/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Runtime/Engine/Private/Components/ActorComponent.cpp] [Line: 918]

libUE4Editor-Core.so!FUnixErrorOutputDevice::Serialize(char16_t const*, ELogVerbosity::Type, FName const&) [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Runtime/Core/Private/Unix/UnixErrorOutputDevice.cpp:70]
libUE4Editor-Core.so!FOutputDevice::LogfImpl(char16_t const*, ...) [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Runtime/Core/Private/Misc/OutputDevice.cpp:71]
libUE4Editor-Core.so!FDebug::AssertFailed(char const*, char const*, int, char16_t const*, ...) [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Runtime/Core/Private/Misc/AssertionMacros.cpp:440]
libUE4Editor-Core.so!FDebug::CheckVerifyFailedImpl(char const*, char const*, int, char16_t const*, ...) [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Runtime/Core/Private/Misc/AssertionMacros.cpp:416]
libUE4Editor-Engine.so!UActorComponent::RegisterComponentWithWorld(UWorld*) [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Runtime/Engine/Private/Components/ActorComponent.cpp:1022]
libUE4Editor-Engine.so!AActor::IncrementalRegisterComponents(int) [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Runtime/Engine/Private/Actor.cpp:4314]
libUE4Editor-Engine.so!AActor::RegisterAllComponents() [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Runtime/Engine/Private/Actor.cpp:4254]
libUE4Editor-Engine.so!AActor::PostSpawnInitialize(FTransform const&, AActor*, APawn*, bool, bool, bool) [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Runtime/Engine/Private/Actor.cpp:3017]
libUE4Editor-Engine.so!UWorld::SpawnActor(UClass*, FTransform const*, FActorSpawnParameters const&) [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Runtime/Engine/Private/LevelActor.cpp:476]
libUE4Editor-Engine.so!UWorld::SpawnActor(UClass*, FVector const*, FRotator const*, FActorSpawnParameters const&) [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Runtime/Engine/Private/LevelActor.cpp:301]
libUE4Editor-Engine.so!UWorld::InternalGetDefaultPhysicsVolume() const [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Runtime/Engine/Private/World.cpp:4324]
libUE4Editor-Engine.so!UWorld::InitWorld(UWorld::InitializationValues) [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Runtime/Engine/Private/World.cpp:1294]
libUE4Editor-Engine.so!UWorld::InitializeNewWorld(UWorld::InitializationValues) [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Runtime/Engine/Private/World.cpp:1505]
libUE4Editor-Engine.so!UWorld::CreateWorld(EWorldType::Type, bool, FName, UPackage*, bool, ERHIFeatureLevel::Type) [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Runtime/Engine/Private/World.cpp:1588]
libUE4Editor-Engine.so!UEngine::Init(IEngineLoop*) [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:1460]
libUE4Editor-UnrealEd.so!UEditorEngine::InitEditor(IEngineLoop*) [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Editor/UnrealEd/Private/EditorEngine.cpp:584]
libUE4Editor-UnrealEd.so!UEditorEngine::Init(IEngineLoop*) [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Editor/UnrealEd/Private/EditorEngine.cpp:822]
libUE4Editor-UnrealEd.so!UUnrealEdEngine::Init(IEngineLoop*) [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Editor/UnrealEd/Private/UnrealEdEngine.cpp:73]
UE4Editor!FEngineLoop::Init() [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Runtime/Launch/Private/LaunchEngineLoop.cpp:3265]
libUE4Editor-UnrealEd.so!EditorInit(IEngineLoop&) [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Editor/UnrealEd/Private/UnrealEdGlobals.cpp:75]
UE4Editor!GuardedMain(char16_t const*) [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Runtime/Launch/Private/Launch.cpp:150]
libUE4Editor-UnixCommonStartup.so!CommonUnixMain(int, char**, int (*)(char16_t const*)) [/home/the_cowboy/unrealworks/UnrealEngine/Engine/Source/Runtime/Unix/UnixCommonStartup/Private/UnixCommonStartup.cpp:243]
libc.so.6!__libc_start_main(+0xef)
UE4Editor!_start()


I am inheriting UBrainComponent, https://github.com/EpicGames/UnrealE…ainComponent.h

Yay! With 55 more minutes worth of “ticks” I found the solution. The idea is to register the component



RegisterComponent();


besides setting



PrimaryComponentTick.bCanEverTick = true;


Furthermore make sure to instantiate the UActorComponent in the following fashion



BrainComponent = NewObject<UMAIBrainComponent>(someactorpointer);


Then the UActorComponent WILL tick!

Thx for the reply, it really works! (And only this works!)

Gonna throw out another solution here after flailing with this issue for few hours (thank you UE4). I’m overriding Tick in my class AAntiGravityTriggerBox which is derived from ATriggerBox, and my object is nested underneath another Basic Cube Actor object in my scene (nested via the Editor, not via my C++ code). I never figured out what, but after object construction and before my BeginPlay is called, something sets various tick flags back off (for example bCanEverTick amongst others, so good luck setting them in the constructor as documentation suggests). Based on the current AActor::RegisterActorTickFunctions implementation, I was able to register my Tick function by adding the following to the top of my BeginPlay override:


void AAntiGravityTriggerBox::BeginPlay()
{
    Super::BeginPlay();
    PrimaryActorTick.Target = this;
    PrimaryActorTick.bCanEverTick = true;
    PrimaryActorTick.SetTickFunctionEnable(true);
    PrimaryActorTick.RegisterTickFunction(GetLevel());

    ...
}