So, I’ve been trying to make some objects in space to be interactable, and for many reasons, the best way that I found to do this was to make a USceneComponent because like this I could make either interactable objects that are attached to some other Actor, or make standalone objects (such as pickup items, like skyrim, fallout 4,etc).
To make it, I created some equivalents to an OnConstruction function that I call in the OnConstruction Script of the blueprint that I create, just so it is easier for a designer to change whatever he needs.
Here is how I’m initializing and making the OnConstruction function of the object:
UInteractableActorComponent::UInteractableActorComponent()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
bWantsBeginPlay = true;
//PrimaryComponentTick.bCanEverTick = true;
Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ObjectMesh"));
Mesh->AttachParent = this;
Mesh->bCastDynamicShadow = false;
Mesh->CastShadow = false;
OnHover3DText = CreateDefaultSubobject<UTextRenderComponent>(TEXT("OnHoverText"));
OnHover3DText->AttachParent = this;
OnHover3DText->bCastDynamicShadow = false;
OnHover3DText->CastShadow = false;
OnHover3DText->SetHorizontalAlignment(EHorizTextAligment::EHTA_Center);
OnHover3DText->SetText(FText::FromString("Vestir"));
OnHover3DText->SetRenderCustomDepth(true);
TextXScale = 1.0f;
TextYScale = 1.0f;
CollisionBox = CreateDefaultSubobject<UBoxComponent>(TEXT("CollisionBox"));
CollisionBox->AttachParent = this;
CollisionBox->bCastDynamicShadow = false;
CollisionBox->CastShadow = false;
CollisionBox->SetCollisionProfileName("Interactable");
CollisionBoxExtent = FVector(10, 10, 10);
}
void UInteractableActorComponent::OnConstruction() {
OnHover3DText->SetRelativeLocation(TextLocation);
OnHover3DText->SetText(InteractionText);
CollisionBox->SetRelativeLocation(CollisionBoxLocation);
CollisionBox->SetBoxExtent(CollisionBoxExtent);
OnHover3DText->SetXScale(TextXScale);
OnHover3DText->SetYScale(TextYScale);
}
And it works like a charm whenever I put only one of those components in an Actor BP, the problem is when I put 2 of these in the same blueprint.
The error happens in the following situtation:
I put 2 of these InteractableActorComponent (let’s call them IAC1 and IAC2), both attached to the root component of the actor blueprint, in the blueprint editor, everythin is as it should be, then I put it in the scene, and everything is still alright, but when I hit Play, the children components (Mesh, OnHover3DText, CollisionBox) of IAC1 attach themselves to IAC2 and I have no idea why.
I’m putting these 2 IACs inside an Elevator class, and here is it’s initialization:
AElevator::AElevator()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
meshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComponent"));
meshComponent->AttachParent = RootComponent;
this->goTop = false;
this->goBot = false;
timeToEndMovement = 5.0f;
}
None of the BeginPlay() of the methods have anything relevant, nor their Tick functions, and I honestly have no idea what else could be bugging it.
Please help T_T
PS: Not sure if any related, but the editor some time crashes whenever I hit Compile recently, but when I build through VS and open it, it runs ok.
Edit: Ok I just found out that what was actually happening is that some of the children components were being duplicated and creating a GEN_VARIABLE with the exact same characteristics, and those were being passed to the other IAC, but I still have no idea why and this is still bugging everything D=