UActorComponent::TickComponent(...) not ticking for some reason.

UE 5.1

Hi all… Not sure what’s happening here but I’ve created an inherited class from UActorComponent.

In the constructor, I’ve set
PrimaryComponentTick.bCanEverTick = true;

Overridden in the header file
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

BeginPlay() called super and even called RegisterComponent()
Originally was not calling RegisterComponent() at all, but read in another post where that helped someone else. But, didn’t affect my problem at all. I’ve tried RegisterComponent() both in the constructor AND here in begin play.
void UCombatComponent::BeginPlay( )
{
Super::BeginPlay( );
RegisterComponent( );
}

TickComponent definition in CPP
void UCombatComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, FString(TEXT(“UCombatComponent::TickComponent”)));
}

I have another project where I’m doing the same thing and it works there, but I am stumped at why it’s not working here.

In my constructor, I’ve set a debug message to print, much like what is here in the TickComponent. The constructor is printing it out, so I know the class is being used and initialized.

I’ve deleted all generated files, deleted the visual studio solution file, regenerated visual studio project files, re-compiled, re-ran app… Nothing.

I’m really up against a time crunch and all here. Hoping someone has some kind knowledge that can help… It will be so greatly appreciated!

Thanks!

Hi m00nb33r,

Have you got Tick enabled in the Owning Actor?

Hi there…

Yes. This component is only being used in one place. In the main character. In the main character’s constructor, it’s tick is enabled.
PrimaryActorTick.bCanEverTick = true;

In the constructor for that character, this is where I’m creating the CombatComponent which, as mentioned inherits from UActorComponent

Combat = CreateDefaultSubobject( TEXT( CombatComponent ) );
Combat->SetIsReplicated(true);|

For grins, I just created a brand new map, set my game mode to my projects game mode, wondering if there was ANYTHING in the scene that could be causing an issue…

no change… a brand new map with nothing in it, just my spawned character from the game mode… Still nothing…

1 Like

Try calling Combat->SetComponentTickEnabled(true) instead of just bCanEverTick - it also sets TickFunctionEnabled.

Hi RecourseDesign

Didn’t make a difference.

Combat = CreateDefaultSubobject( TEXT( CombatComponent ) );
Combat->SetComponentTickEnabled(true);
Combat->SetIsReplicated(true);

I don’t think I called this method to get it going (I can’t for the life of me find my source code), but it looks promising:

I’m going through a course a second time. I started it back last spring, but got side tracked with life. Finally had a chance go continue but decided to start all over again because I had forgotten so much.

Comparing my old code to this new code, nothing is different… In fact, as I progress though the course often times, I’m just copy pasting from the old project to this new project.

Also, old project was done in 5.0 preview. Right before I started this again, I upgraded the old project to 5.1. Compiled, ran fine… THEN I started this new one from scratch…

Everything was moving along nicely till now.

ALL THAT, to say…

I never had to do anything with registering stuff in the past. I’ll take a peek into this though.

EDIT
Tried it… UE tosses an error when I try to launch the editor.

1 Like

I have a function on this CombatComponent that gets called LONG after any initialization, in fact, this functionality will only happen when I pick up a a weapon… So, I figured it was a safe place to try this

if (PrimaryComponentTick.bCanEverTick)
{
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, FString(TEXT(“Ticks are enbabled”)));
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red, FString(TEXT(“Ticks got disabled” )));
}

Always prints Ticks are enabled.

So, the they are always enabled, or at least the boolean value is true, but, something is preventing this function from being called.
void UCombatComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)

There’s also the console command “dumpticks” which lists all actors and components with ticks enabled to the log file…

Just throwing ideas around - did you try doing a “Combat->RegisterComponent()” straight after creating it? before you set TickEnabled to true…

Another thing, I used “AddComponentByClass” rather than CreateDefaultSubobject

I have done Combat->RegisterComponent(). No change.

Hate to ask, but do you have an example of using AddComponentByClass?
Not finding any out on the internet. UE Docs didn’t really help me much.

Here’s some code from a project I know works…

UChildActorComponent* ArdActor::rdAddChildComponent(UClass* actorClass,const FTransform& transform) {

#if ENGINE_MAJOR_VERSION>4 || ENGINE_MINOR_VERSION>25
	UChildActorComponent* cac=(UChildActorComponent*)AddComponentByClass(UChildActorComponent::StaticClass(),false,transform,false);
#else
	UChildActorComponent* cac=NewObject<UChildActorComponent>(this,UChildActorComponent::StaticClass());
    cac->RegisterComponent();
	cac->SetRelativeTransform(transform);
#endif

	cac->AttachToComponent(GetRootComponent(),FAttachmentTransformRules::KeepRelativeTransform);
	cac->SetChildActorClass(actorClass);

	return cac;
}

you can use FTransform::Identity for the transform…

Thanks, I’ll give this a shot.

1 Like

Two issues
For some reason does not like Combat->AttachToComponent(…).
Plus, when I launch UE, UE throws an exception on Combat->SetIsReplicated(true).

#if ENGINE_MAJOR_VERSION>4 || ENGINE_MINOR_VERSION>25
	Combat = (UCombatComponent*)AddComponentByClass(UCombatComponent::StaticClass( ), false, FTransform::Identity, false);
 	
#else
 	Combat = NewObject<UCombatComponent>(this, UCombatComponent::StaticClass( ));
	Combat->RegisterComponent( );
 	Combat->SetRelativeTransform(FTransform::Identity);
 #endif
 	
 	Combat->AttachToComponent( GetRootComponent(), AttachmentTransformRules::KeepRelativeTransform);
 	Combat->SetIsReplicated(true);
1 Like

The 2nd parameter (bManualAttachment) when false does the attachment, try setting it to true, or leave as false and comment that out. It shouldn’t matter though - it’s just attaching it twice - it’s possible “Combat” is null…

maybe add a “check(Combat)” straight after the AddComponent.

Well, what I meant is, is that AttachToCompont(…) is not a function on the CombatComponent class.

class PIRATEBOOTY_API UCombatComponent : public UActorComponent

Right now, Combat is a member variable on a PirateCharacter which is
class PIRATEBOOTY_API APirateCharacter : public ACharacter

Everything in the CombatComponent was working except for tick
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

I did as you suggest, I called check(Combat). When I launch the editor, UE aborts and errors.

I was getting the exact same error when trying to use
Combat->SetIsReplicated(true);

Ok, yes sorry - that’s part of USceneComponent - it can be left out.

But that “check” is indicating that the AddComponentByClass has failed for some reason.

What happens if you subclass Combat from USceneComponent rather than UActorComponent?

Tried your suggestion, didn’t work…

For grins I just created a brand new class. Created it in the PirateCharacter class like I was with the Combat component… Put a debug statement in it’s Tick function… New BattleComponent ticks like a charm…

Blown away at why this CombatComponent won’t tick.

edit
I wasn’t using the AddComponentByClass like you suggest, I was using the CreateDefaultSubObject… When I changed to USceneComponent

ANyway, I changed to USceneComponent, then tried to create it the way you suggested, but UE crashed as soon as I ran the app

Fatal error: [File:D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp] [Line: 4229] NewObject with empty name can't be used to create default subobjects (inside of UObject derived class constructor) as it produces inconsistent object names. Use ObjectInitializer.CreateDefaultSubobject<> instead.

I’ve noticed on the forum that quite a number of people have found that tick stops on the components (added from the Blueprint Outliner) - and they’ve been able to fix it by removing it and then re-adding, which kind of sounds like a bug - but this has been going on for years - I guess it is possible that it’s a bug.

The fact that AddComponent is failing is just strange!

Yeah it’s got my head spinning…