// Sets default values
ANPC::ANPC()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;
// Called when the game starts or when spawned
void ANPC::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ANPC::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void ANPC::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
I will try to address the problems you faced as best i can. So first up, the overlap event didn’t fire probably because you don’t have the custom function “OnOverlapBegin” setup as a UFUNCTION() like so
Next thing is you should attach your components to the root right after you create them, that would fix the scaling problem and the box being far from your character.
I can see that you have a root component already so just ignore the SceneComponent lines, and btw the SetHiddenInGame(true) for the TextRenderer should work just fine, it did for me.
Also i recommend using InitBoxExtent instead of the scaling method, but scaling will work as well.
Thanks for the reply. I’ve made some changes and now seems to works, but when the function is called the editor crash, i suppose the TextRenderer is null. Can you find the error?
.h
UCLASS(Blueprintable, ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class SCROLLERGAME_API ANPC : public AActor, public IIInteract
{
GENERATED_BODY()
public:
ANPC();
UPROPERTY(EditAnywhere, Category = TextRenderer, meta = (AllowPrivateAccess = "true"))
class UTextRenderComponent* TextRenderer;
UPROPERTY(EditAnywhere, Category = BoxComponent, meta = (AllowPrivateAccess = "true"))
class UBoxComponent* BoxComponent;
UPROPERTY(EditAnywhere, Category = IdleAnimation, meta = (AllowPrivateAccess = "true"))
class UPaperFlipbookComponent* IdleAnimation;
UPROPERTY(EditAnywhere, Category = SceneRoot, meta = (AllowPrivateAccess = "true"))
class USceneComponent* SceneRoot;
UFUNCTION()
void OnOverlapBegin(..);
};
I’m not seeing any reason for it to crash, can you try removing the actor from the scene and placing it again after compiling the blueprint? sometimes placed actors don’t update when you change its components.
If that doesn’t work, please take a screenshot of the crash log.
Well, you were right about TextRenderer being null, uhm is there any custom logic in the blueprint at all? Can you check if the TextRenderer is correctly set up inside the blueprint? Maybe you could try deleting the blueprint completely and making a new one?
Sometimes changing components and the root in C++ messes up already existing blueprints so keep that in mind while working in the future in case something doesn’t behave the way you think it should. No problem mate, glad i could help