Hi, i created new object and when i spawn it into the world it does spawn in one specific spot and when i try to move it, it snaps back to it’s original position. How can i solve this? Here is a video showing my problem: https://www.youtube.com/watch?v=NSY3kAWAwrA . I can move every other object in the world but not that one i’m creating. Thanks.
Your root component requires a transform for it to be movable.
So you can use a USceneComponent as the root for example or a static mesh component.
Please show the code inside of the moving platform.
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
include “CoreMinimal.h”
include “GameFramework/Actor.h”
include “MovingPlatform.generated.h”
UCLASS()
class UNREALLEARNINGKIT_API AMovingPlatform : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor’s properties
AMovingPlatform();
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)
int32 MyInt = 99;
UPROPERTY(EditAnywhere)
float MyFloat = 5.99;
UPROPERTY(EditAnywhere)
bool MyBool = true;
};
Try adding a scene component to your class
UPROPERTY(EditAnywhere, BlueprintReadWrite)
USceneComponent* Root;
and inside of the cpp initialize it in the CDO (AMovingPlatform ::AMovingPlatform() )
Root = CreateDefaultSubobject<USceneComponent>(TEXT("root"));
You should then be able to move it.
The first component that registers will automatically become the root component.
Thank you very much, it’s working