ユーザ用ツール

サイト用ツール

wiki:ue4:tips:501

以前のリビジョンの文書です


コンポーネントの追加(4.7.3)

  1. 「詳細パネル」の「新規コンポーネントの追加」から「新規C++コンポーネントの追加…」を選択する。
  2. 「ActorComponent」を選択して次へ進む。
  3. 「MyActorComponent」など名前を付けて「クラスを作成」する。

<sxh cpp; title: MyActorComponent.h> class STDPROJECT_API UMyActorComponent : public UActorComponent {

  GENERATED_BODY()

private:

  // 追加
  float m_fRunningTime;

} </sxh>

<sxh cpp; title: MyActorComponent.cpp> 開始時に呼ばれる void UMyActorComponent::InitializeComponent() { Super::InitializeComponent(); } 毎フレーム呼ばれる void UMyActorComponent::TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) {

  Super::TickComponent( DeltaTime, TickType, ThisTickFunction );
  // 追加
  AActor* pOwner = GetOwner();
  FVector NewLocation = pOwner->GetActorLocation();
  float DeltaHeight = (FMath::Cos(m_fRunningTime + DeltaTime) - FMath::Cos(m_fRunningTime));
  NewLocation.X += DeltaHeight * 20.0f;
  m_fRunningTime += DeltaTime;
  pOwner->SetActorLocation(NewLocation);

} </sxh>

動作はCos移動するだけの物を実装してみました。プロジェクトをビルドしてエラーが出ないことを確認します。

  1. UE4エディターに戻って「MyActorComponent」を任意のアクターに割り当てます。

これで再生するとアクターが動くはずですが、もし動かない場合は「アクターの可動性」が「スタティック」になっているので、「ムーバブル」に変更します。

Permalink wiki/ue4/tips/501.1429674688.txt.gz · 最終更新: 2015/04/27 13:26 (外部編集)

oeffentlich