UE4学习笔记3——问题及解决方案

以插件名 SimpleWindow 为例:

  • 编译无法通过,可能是没有添加 *PCH.h 预编译文件头,在 Private 目录下新建文件:插件名+PrivatePCH.h 的文件,即SimpleWindowPrivatePCH.h ,内容为:
#include "SimpleWindow.h"

// UObject core
#include "CoreUObject.h" //默认是不含这个的

// Actor based classes
#include "GameFramework/Character.h" //包插件中所有用的的引擎类都丢到这里来

//预先定义日志宏
DEFINE_LOG_CATEGORY_STATIC(MyLog, Warning, All);

        使用方法:在后添加的所有自定义 .cpp 文件头添加此文件,即 

#include "SimpleWindowPrivatePCH.h"
  • 无法打开源文件 XX.h ,右击项目->属性->VC++目录,在包含目录添加 $(ProjectDir); 如下图:

  • 自定义Slate常用相关头文件
#include "DeclarativeSyntaxSupport.h"  //Slate宏语法支持
#include "SCompoundWidget.h" //混合窗口类型
#include "SBoxPanel.h" //UI布局类型,例如水平、垂直、覆盖
  • 获取场景中Actor实例的两种方法
#include "Kismet/GameplayStatics.h"
#include "Runtime/Engine/Public/EngineUtils.h"

void AMyActor::BeginPlay()
{
    //方法一:通过迭代器
    Super::BeginPlay();
    for (TActorIterator<AMyActor> Iterator(GetWorld()); Iterator; ++Iterator) 
    {
        if (Iterator->GetName() == FString("MyActor_BP4")) //注意,此处Actor的name为id_name,具有唯一性,不是display_name
                {
                    Iterator->PrintMessage(TEXT("通过TActor找到Actor&调用PringMessage函数"));
                }
    }

    //方法二:通过数组遍历世界元素
    TArray<AActor*> _TempArryActors;
    UGameplayStatics::GetAllActorsOfClass(GetWorld(), AActor::GetClass(), _TempArryActors);
    for (int32 i = 0; i < _TempArryActors.Num(); i++)
    {
        Cast<AMyActor>(_TempArryActors[i])->PrintMessage(TEXT("通过UGameplay找到Actor&调用PringMessage函数"));
    }
    //this->PrintMessage(FString("testMessage"));
}

  • 不允许指向不完整的类类型:
    没有 include 相关头文件


猜你喜欢

转载自blog.csdn.net/qq_35221523/article/details/79883208