Download

Need Help! c++ Register Tick function in a UStaticMeshComponent (engine version 4.12.4)

I would like to implement a custom gameplay using my static mesh component and i’m using C++. I am not able to call Tick function in the static mesh component.
I could still do the same job by creating a custom class and connecting it to actor Tick manually


	TArray<UActorComponent*> ho = GetComponentsByClass(UHoverComponent::StaticClass());
	for (UActorComponent* a : ho) {
		if (a != nullptr) Cast<UHoverComponent>(a)->ComponentTick();
	}

but I don’t want to do that because it is not efficient and I want my component to be isolated and used with other actors too.

Can some one help me to register my custom function to Tick event or anyway to call the Tick function in UStaticMeshCompoenent. (engine version 4.12.4)

The way to implement your own tick is installing a callback per FTickerDelegate, e.g. in your game instance.


// Register delegate for ticker callback
    FTickerDelegate TickDelegate = FTickerDelegate::CreateUObject(this, &UMyGameInstance::tick);
    // save the handle
    TickDelegateHandle = FTicker::GetCoreTicker().AddTicker(TickDelegate);

I just have error in creating the delegate


Tickdelegate = FTickerDelegate::CreateUObject(this, &UHoverComponent::ComponentTick);

the Error: 498ebfd4c57deeb0a9813c6477daa0175c704700.jpeg

I think we are missing out something

Fixed: The return value of the function has to be bool and parameter as float