What does your Pickup class represent in the game exactly? Are you sure it is wise to derive it from AActor? Wouldn’t AStaticMeshActor be more appropriate? Or maybe an actor component? It all depends what the role of this pickup class is.
I need a spawnable Actor which plays the role of a classic pickup in videogames… like in Unreal.
But **what I really need **is a way to give my Actor a StaticMesh (3D model) through C++ **AND BE ABLE TO EDIT IT’S PROPERTIES **(scale, rotate) through the Blueprint-child class
Hrm, so it seems like the forums no longer automatically subscribe me to threads I have commented on. Sorry for missing your response to my question.
I recreated my test project in 4.17.2, and my actor appears to be rotating there as well. This is what I have in the code class, which I believe matches what you have set up:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"
UCLASS()
class TESTROTATION1_API AMyActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AMyActor();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = TestCat)
UStaticMeshComponent* PickupMesh;
};
------------------------------------------------
#include "MyActor.h"
// Sets default values
AMyActor::AMyActor()
{
// 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;
USceneComponent* SceneComp = CreateDefaultSubobject<USceneComponent>(TEXT("SceneComp"));
PickupMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PickupMesh"));
RootComponent = SceneComp;
PickupMesh->SetupAttachment(SceneComp);
}
// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AMyActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
FRotator Rotation = FRotator(0.f, 1.f, 0.f);
AddActorWorldRotation(Rotation);
}
When I create a Blueprint from that class, set a static mesh, then place it in the level, the actor appears to rotate when I start PIE. Is there anything that I have different from how you are setting up your class and Blueprint?
Thank you for the additional code. It looks like the issue is happening with this line:
PickupMesh->SetSimulatePhysics(true);
With physics set to simulate on the static mesh component, it essentially detaches that component from its parent component. If you simulate the project, you can see that the root scene component is rotating as expected, but the static mesh is not because it has been separated from the root component. As far as the Blueprint is concerned they are still connected, but in terms of movement they are each doing their own thing.
If you need to have the entire actor, and all of its components, rotate as a single entity, then you won’t be able to turn on Simulate Physics. If you need the static mesh to simulate physics, then you will need to make sure to rotate that component in sync with the actor itself.