前言
開新系列,不知道能活多久。
總之就是紀錄UE5學習的過程。
目標是用C++做出Flappy bird。
專案Missing parent class
有時候重開UE5會發現繼承自C++腳本的blueprint無法使用。
解法1 (來源)
- Close ide and project,and then open again the project
- In World Settings/ GameMode override,i select MyGameModeBase (derived from GameModeBase),this is fundamental!
- if i open visual studio,the project is there,with all the code.
- AND EVERYTHING WORKS
解法2
不要用Epic launcher開UE,直接從.sln開啟VS專案,再F5 build出UE。 我覺得這個比較好用,缺點是VS crash掉要重build UE。
USceneComponent
如果沒有指定Root Component,UE會自己找一個component當作root。若沒有特別設定,則pivot會在Mesh的中心點。
很慘的是UE的collider跟Mesh綁在一起,且collider也沒有像Unity可以調整offset。
我們可以創個空物件,再把Mesh創在他下面:
USceneComponent 定義: 只具備transform的空物件,適合用來調整offset。
This makes USceneComponent useful as a ‘dummy’ component in the hierarchy to offset others. For example, you might use a USceneComponent as a pivot point for rotating other components, or as a placeholder that other components can be attached to.
自訂類別屬性欄位
類似Unity的public參數會直接顯示在inspector,UE範例:
UPROPERTY(EditDefaultsOnly, Category = "Components") TSubclassOf<class 你的類別> 參數名
生成
GetWorld()->SpawnActor<你的類別>( prefab名稱 , position , roatation );
定時生成
定時執行特定方法:
GetWorldTimerManager().SetTimer(FTimerHandle類別 , this , &目標方法, 間隔時間 , true );
FTimerHandle概念類似Unity的Coroutine = StartCoroutine(...),之後可以執行Stop等功能管理。