Announcement

Collapse
No announcement yet.

Component moves when actor added to level

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • replied
    Hmm, works when I copy/pasted your constructor. Thanks!

    Leave a comment:


  • replied
    Put in here?
    Code:
    // Sets default values
    AFacilityLight::AFacilityLight()
    {
    	// 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;
    	Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComp"));
    	RootComponent = Mesh;
    	Light = CreateDefaultSubobject<UPointLightComponent>(TEXT("LightComp"));
    	Light->SetupAttachment(Mesh);
    }

    Leave a comment:


  • replied
    Doesn't work :/

    Leave a comment:


  • replied
    hi! try it:
    Code:
    Light->SetupAttachment(Mesh);

    Leave a comment:


  • started a topic Component moves when actor added to level

    Component moves when actor added to level

    Heyo!

    This bug is the bane of my life...

    This has been happening for lots of my actors, but this is the clearest example.
    So, I have a class for a Light object, pretty basic:
    h:
    Code:
    // Fill out your copyright notice in the Description page of Project Settings.
    
    #pragma once
    
    #include "GameFramework/Actor.h"
    #include "FacilityLight.generated.h"
    
    UCLASS()
    class HSHOOTER_API AFacilityLight : public AActor
    {
    	GENERATED_BODY()
    	
    public:	
    	// Sets default values for this actor's properties
    	AFacilityLight();
    
    	// Called when the game starts or when spawned
    	virtual void BeginPlay() override;
    	
    	// Called every frame
    	virtual void Tick( float DeltaSeconds ) override;
    
    	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Mesh)
    	class UStaticMeshComponent* Mesh;
    	
    	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gameplay)
    	UPointLightComponent* Light;
    
    	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Animation)
    	int FluctuationRate;
    
    	void SwitchLight(bool b);
    };
    cpp:
    Code:
    // Fill out your copyright notice in the Description page of Project Settings.
    
    #include "HShooter.h"
    #include "FacilityLight.h"
    
    
    // Sets default values
    AFacilityLight::AFacilityLight()
    {
     	// 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;
    	Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComp"));
    	Light = CreateDefaultSubobject<UPointLightComponent>(TEXT("LightComp"));
    
    	RootComponent = Mesh;
    }
    
    // Called when the game starts or when spawned
    void AFacilityLight::BeginPlay()
    {
    	Super::BeginPlay();
    	
    }
    
    // Called every frame
    void AFacilityLight::Tick( float DeltaTime )
    {
    	Super::Tick( DeltaTime );
    	Light->SetIntensity(Light->Intensity + (FluctuationRate*sin(rand() % 360)));
    
    }
    
    void AFacilityLight::SwitchLight(bool b)
    {
    	Light->SetVisibility(b);
    }
    And I have a blueprint child of this class.
    In the blueprint editor, I have made sure the point light component is where it should be in the lampshade:
    Click image for larger version

Name:	Capture1.PNG
Views:	1
Size:	830.1 KB
ID:	1215824

    However, when I drag it into the level, the component moves!
    Click image for larger version

Name:	Capture2.PNG
Views:	1
Size:	939.5 KB
ID:	1215825

    The only fix I know, is to set location in BeginPlay() which is horrible, and messy.

    Anybody know how to fix this?
Working...
X