201611221740
1.在UE4中,生成C++代码工程,如何修改选定的游戏模式
在UE4中,生成C++代码工程,其游戏模式默认指定跟工程名相关的自动生成的模式,选用该模式必须使用代码去指定;
当然,你可以用继承GameMode的蓝图去替换原来的的游戏模式,则可以在编辑器中修改选定的游戏模式,如果代码生成的没有
复杂的逻辑,可以创建GameMode的蓝图,这样操作方便一点
2.如何在代码中指定,选定游戏模式相关的(以下代码一般写在游戏模式的构造函数中)
2.1如果有蓝图资源,则利用ConstructHelpers::FClassFinder去寻找;
eg:
static ConstructorHelpers::FClassFinder<APawn> PlayerPawnBPClass(TEXT("Blueprint'/Game/Blueprint/FPCharacter'"));
if (PlayerPawnBPClass.Class != NULL)
{
DefaultPawnClass = PlayerPawnBPClass.Class;
}
注意:在这里复制资源引用时要去掉后面的格式
Blueprint'/Game/Blueprint/FPCharacter.FPCharacter' ==》Blueprint'/Game/Blueprint/FPCharacter'
2.2如果,用代码创建了一个完整的,如角色,无需编辑器额外编辑;则可以使用 类名::StaticClass()去指定
eg:DefaultPawnClass = ABMCharacter::StaticClass();
3.在虚幻中,如何利用纹理向屏幕中画一个东西;如射击类游戏中的瞄准器?
3.1.通过UE4的向导创建继承与HUD的类
3.2.重写绘制函数virtual void DrawHUD() override;绘制函数中,主要是确定绘制点,绘制资源,绘制颜色,以及混合模式
eg:
BMHUD.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/HUD.h"
#include "BMHUD.generated.h"
/**
*
*/
UCLASS()
class BOSSMODE_API ABMHUD : public AHUD
{
GENERATED_BODY()
public:
ABMHUD();
// Primary draw call for the HUD [11/17/2016 Administrator]
virtual void DrawHUD() override;
private:
// Crosshair asset pointer [11/17/2016 Administrator]
class UTexture2D* CrosshairTex;
};
BMHUD.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "BossMode.h"
#include "BMHUD.h"
ABMHUD::ABMHUD()
{
// Set the crosshair texture
static ConstructorHelpers::FObjectFinder<UTexture2D> CrosshiarTexObj(TEXT("Texture2D'/Game/FirstPerson/Textures/FirstPersonCrosshair.FirstPersonCrosshair'"));
if (CrosshiarTexObj.Succeeded())
{
CrosshairTex = CrosshiarTexObj.Object;
}
}
void ABMHUD::DrawHUD()
{
Super::DrawHUD();
// find center of the Canvas
const FVector2D Center(Canvas->ClipX * 0.5f, Canvas->ClipY * 0.5f);
// offset by half the texture's dimensions so that the center of the texture aligns with the center of the Canvas
const FVector2D CrosshairDrawPosition((Center.X - (CrosshairTex->GetSurfaceWidth() * 0.5)), (Center.Y - (CrosshairTex->GetSurfaceHeight() * 0.5f)));
// draw the crosshair
FCanvasTileItem TileItem(CrosshairDrawPosition, CrosshairTex->Resource, FLinearColor::White);
TileItem.BlendMode = SE_BLEND_Translucent;
Canvas->DrawItem(TileItem);
}
3.3.最后在游戏模式类中指定HUDClass
eg:
HUDClass = ABMHUD::StaticClass();
4.PCH文件出错后,怎么处理?
排除错误,代码重新用UE4打开原工程,如果能打开,说明你已经成功排除错误,且PCH自动恢复
5.如果要把枚举类型的值传到蓝图编辑器中,需要在c++语法上加上UENUM(BlueprintType),并且在传这种类型的变量时,需要用TEnumAsByte模板修饰;注意:该类型的set和get方法如果需要蓝图能调用,则
set方法需要有返回bool类型的值
6.如果发现UE4代码写的绑定实现,编译通过,在蓝图中没有起作用怎么办?
可能的原因:
1.在函数声明中没有UFUNCTION()修饰,该宏是通知UE4引擎知道自己实现的代理函数;
2.事件的绑定,需要重新创建一个蓝图去继承自己实现的类;因为现在的引擎实现不了我们更新了时间的绑定,而实时改变蓝图的功能

浙公网安备 33010602011771号