【发布时间】:2018-03-03 07:50:00
【问题描述】:
我已经制作了一个简单的脚本,就像在视频教程中一样。它编译没有错误,当我按下播放按钮时,引擎崩溃。为什么会这样?
.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Components/StaticMeshComponent.h"
#include "MyActor.generated.h"
UCLASS()
class ROTATION_API AMyActor : public AActor
{
GENERATED_BODY()
public:
AMyActor();
protected:
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
};
.cpp
#include "MyActor.h"
AMyActor::AMyActor()
{
PrimaryActorTick.bCanEverTick = true;
}
void AMyActor::BeginPlay()
{
Super::BeginPlay();
FString a = GetOwner()->GetName(); // ERROR
}
void AMyActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
【问题讨论】:
-
完全不了解 Unreal:
GetOwner()->GetName()闻起来像 nullptr。GetOwner()在某些情况下是否返回nullptr? -
@user2328447 我猜是的,但不知道为什么。它不应该为空,它可以在视频教程中使用
标签: c++ unreal-engine4