UE4:演员在被击中后消失了

问题描述 投票:0回答:1

我使用的是虚幻引擎4.25版本。我创建了一个角色,并将其放在一个空白模板上。该角色在编辑器中是可见的,但一旦点击播放按钮,该角色就变得不可见了。我试图用我的代码来移动这个对象。

下面是代码。

MyActor. cpp

#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;

    Dimensions = FVector(10, 0, 0);
    AxisVector = FVector(1, 0, 0);
    Location   = FVector(1, 0, 0);
    Multiplier = 50.f;

}

// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
    Super::BeginPlay();

}

// Called every frame
void AMyActor::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);



    // Updates the angle of the object
    AngleAxis += DeltaTime * Multiplier;

    if (AngleAxis >= 360.0f)
    {
        AngleAxis = 0;
    }

    //Rotates around axis
    FVector RotateValue = Dimensions.RotateAngleAxis(AngleAxis, AxisVector);

    Location.X += RotateValue.X;
    Location.Y += RotateValue.Y;
    Location.Z += RotateValue.Z;

    SetActorLocation(Location, false, 0, ETeleportType::None);

}

MyActor.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"

UCLASS()
class ROBOTEURS_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;

    // declare our float variables
    UPROPERTY(EditAnywhere, Category = Movement)
        float AngleAxis;

    UPROPERTY(EditAnywhere, Category = Movement)
        FVector Dimensions;

    UPROPERTY(EditAnywhere, Category = Movement)
        FVector AxisVector;

    UPROPERTY(EditAnywhere, Category = Movement)
        FVector Location;

    UPROPERTY(EditAnywhere, Category = Movement)
        float Multiplier;

};

到底是什么地方出了问题?

c++ graphics unreal-engine4 game-development
1个回答
0
投票

这就解决了,我没有创建一个网格。https:/www.youtube.comwatch?v=30XEdBoPw6c

我添加了以下内容。

.cpp

AMyActor::AMyActor()
{
    ...
    Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
    RootComponent = Root;

    Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
    Mesh->AttachTo(Root);

    ...
}

.h

public: 
    ...

    UPROPERTY()
        USceneComponent* Root;

    UPROPERTY(EditAnywhere)
        UStaticMeshComponent* Mesh;
    ...
© www.soinside.com 2019 - 2024. All rights reserved.