【问题标题】:UE4: Actor disappears after play is hitUE4:角色在播放后消失
【发布时间】:2020-08-24 09:11:55
【问题描述】:

我使用的是虚幻引擎 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;

};

可能出了什么问题?

【问题讨论】:

  • 你的actor没有组件,更不用说任何可渲染的组件了。你希望在游戏中看到什么?
  • @Rotem,我对此完全陌生。你能告诉我要查什么吗?或者请解释一下?
  • 您在编辑器中看到了什么是您希望在游戏中看到的?您的演员没有视觉表现,例如某种网格组件。
  • 我在编辑器中看到我的对象。我希望物体在游戏过程中绕圈移动。
  • 你的对象是什么样子的?

标签: c++ graphics unreal-engine4 game-development


【解决方案1】:

这修复了它,我没有创建网格: https://www.youtube.com/watch?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;
    ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-23
    • 1970-01-01
    • 2021-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多