diff --git a/Source/InstancedMeshLineRendering/Private/GPUInstancedLineComponent.cpp b/Source/InstancedMeshLineRendering/Private/GPUInstancedLineComponent.cpp index c48e28501c634fd9e2eacd497b268e2ea3ba17d5..687d43f5644036086f2697aab03c51a2cc180176 100644 --- a/Source/InstancedMeshLineRendering/Private/GPUInstancedLineComponent.cpp +++ b/Source/InstancedMeshLineRendering/Private/GPUInstancedLineComponent.cpp @@ -18,10 +18,6 @@ UGPUInstancedLineComponent::UGPUInstancedLineComponent(const FObjectInitializer& TextureWidth = 2048; TextureHeight = 2048; - //PrimaryComponentTick.bCanEverTick = true; - //bTickInEditor = true; - //bAutoActivate = true; - SetWorldTransform(FTransform::Identity); SetUsingAbsoluteLocation(true); @@ -43,6 +39,18 @@ UGPUInstancedLineComponent::UGPUInstancedLineComponent(const FObjectInitializer& //DynamicLineMaterial = UMaterialInstanceDynamic::Create(LineMaterialInterface, GetTransientPackage()); SetMaterial(0, DynamicLineMaterial); SetMobility(EComponentMobility::Static); + +#if WITH_EDITOR + bAutoActivate = true; + PrimaryComponentTick.bCanEverTick = true; + bTickInEditor = true; + SetComponentTickEnabled(true); +#else + PrimaryComponentTick.bCanEverTick = false; + bTickInEditor = false; + SetComponentTickEnabled(false); +#endif + } UGPUInstancedLineComponent::~UGPUInstancedLineComponent() @@ -407,6 +415,22 @@ void UGPUInstancedLineComponent::OnUpdateTransform(EUpdateTransformFlags UpdateT SetWorldTransform(FTransform::Identity); } +void UGPUInstancedLineComponent::TickComponent(float DeltaTime, ELevelTick TickType, + FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + if(TickCount < MaxTicksUntilInit) + { + TickCount++; + } + else + { + Init(); + bTickInEditor = false; + SetComponentTickEnabled(false); + } +} + #endif diff --git a/Source/InstancedMeshLineRendering/Public/GPUInstancedLineComponent.h b/Source/InstancedMeshLineRendering/Public/GPUInstancedLineComponent.h index a7f01c49e81b66cd3b4ceaa0870565d1a4a03b3b..2dbfe14ec283739aa35f2573988c2d2cc931052d 100644 --- a/Source/InstancedMeshLineRendering/Public/GPUInstancedLineComponent.h +++ b/Source/InstancedMeshLineRendering/Public/GPUInstancedLineComponent.h @@ -104,7 +104,9 @@ public: virtual void PostEditChangeChainProperty(FPropertyChangedChainEvent& PropertyChangedEvent) override; virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override; // need this for the widget as for some godforsaken reason the Chain event doesn't fire... // This is ABSURDLY hacky - virtual void OnUpdateTransform(EUpdateTransformFlags UpdateTransformFlags, ETeleportType Teleport = ETeleportType::None) override; + virtual void OnUpdateTransform(EUpdateTransformFlags UpdateTransformFlags, ETeleportType Teleport = ETeleportType::None) override; + + virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; #endif //virtual TStructOnScope<FActorComponentInstanceData> GetComponentInstanceData() const override; @@ -484,6 +486,11 @@ public: UPROPERTY(Transient) bool bIsInitialized = false; + + private: + // hacky way to initialize components. + uint32 TickCount = 0; + uint32 MaxTicksUntilInit = 5; };