C++,在UE4中写Hello World!!

来源:互联网 发布:英语口语听力训练软件 编辑:程序博客网 时间:2024/05/17 09:28

IDE : Visual Studio2017
UE版本:4.17.2

首相创建C++项目

这里写图片描述

在项目浏览器中打开默认的模式,(如果没有去右下角视口选项)

这里写图片描述
这时候会启动Visual Studio

然后在CPP中写入代码

// Fill out your copyright notice in the Description page of Project Settings.#include "FPSProjectGameModeBase.h"#include "Engine.h"void AFPSProjectGameModeBase::StartPlay(){    Super::StartPlay();    if (GEngine)    {        // 显示调试信息五秒。         // -1“键”值(首个参数)说明我们无需更新或刷新此消息。        GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("   Hello   World   !!!"));    }}

然后在.h中写入代码

// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"#include "GameFramework/GameModeBase.h"#include "FPSProjectGameModeBase.generated.h"/** *  */UCLASS()class FPSPROJECT_API AFPSProjectGameModeBase : public AGameModeBase{    GENERATED_BODY()    virtual void StartPlay() override;};

右键生成一下
这里写图片描述

回到编辑器,把游戏模式修改成我们刚写的
这里写图片描述

然后启动项目
这里写图片描述

总结:
其实就是一段输出代码就好

GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("   Hello   World   !!!"));

然后要包含头文件include

原创粉丝点击