UE4學習筆記: Functions

來源:互聯網
上載者:User
函式宣告 UE4中有兩種函數, 一種是傳統的C++函數, 一種是UFunction. UFunction通過加入一些描述符來支援一些特殊功能
UFUNCTION([specifier, specifier, ...], [meta(key=value, key=value, ...)])ReturnType FunctionName([Parameter, Parameter, ...])
主要有幾種應用: 在Blueprint中調用 做為delegate, 如與按鍵訊息進行綁定 網路回調和資料同步 做為命令列的指令執行, 同UE3的exec關鍵字
函數說明符 Blueprint相關 BlueprintAuthorithOnly: 沒有網格授權的話不會在blueprint中執行 BlueprintCallable: 可以在blueprint中執行 BlueprintCosmetic: 表現函數, 不會在伺服器執行 BlueprintImplementableEvent: 可以在blueprint中重寫 BlueprintNativeEvent: 設計為被blueprint重寫, 但是仍然包含native的實現 BlueprintPure: 不會影響自身對象 Network相關 Client: 只在用戶端執行 Server: 只在服務端執行 NetMulticast: 會在伺服器和所有用戶端執行 Reliable: 函數執行通過網路進行複製, 並且是可靠的 Unreliable: 函數在複製執行時可能失敗 Editor相關 Category 其它 CustomThunk: 提供自訂的execFoo, 而不是產生的 Exec: 可以在命令列中被執行 中繼資料說明符 BlueprintInternalUseOnly BlueprintProtected: 只在blueprint中調用 DeprecatedFunction DeprecationMessage UnsafeDuringActorConstruction 函數參數說明符 Out: 傳引用 Optional: 可選, 取預設值
委託(Delegate)
DECLARE_DELEGATE_OneParam( FStringDelegate, FString );

FSharedRef< FLogWriter > LogWriter( new FLogWriter() );WriteToLogDelegate.BindSP( LogWriter, &FLogWriter::WriteToLog );
WriteToLogDelegate.Execute( TEXT( "Delegates are spiffy!" ) );

建議Delegate傳遞時使用引用, 避免傳值引起記憶體配置 multi-cast與event的區別只有聲明event的類本身可以調用event的Broadcast, IsBound, Clear函數 dynamic delegate是用函數名進行綁定, 所以可以進行序列化, 但速度相對較慢
定時器(Timer)
GetWorldTimerManager().SetTimer(this, &AMatineeActor::CheckPriorityRefresh, 1.0f, true);
GetWorldTimerManager().ClearTimer(this, &AMatineeActor::CheckPriorityRefresh);
GetWorldTimerManager().IsTimerActive(this, &APlayerController::DelayedPrepareMapChange)
Timer不是安全執行緒的, 只能在遊戲線程使用





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.