Advertisement
Guest User

MySceneComponent.cpp

a guest
Jul 23rd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3. #include "HowTo_Components.h"
  4. #include "OrbitMovementComponent.h"
  5. #include "MySceneComponent.h"
  6.  
  7.  
  8. // Sets default values for this component's properties
  9. UMySceneComponent::UMySceneComponent()
  10. {
  11.     // Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
  12.     // off to improve performance if you don't need them.
  13.     PrimaryComponentTick.bCanEverTick = true;
  14.    
  15.     UStaticMeshComponent* SphereVisual = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("VVisualRepresentation"));
  16.     SphereVisual->SetupAttachment(this);
  17.     static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere"));
  18.     if (SphereVisualAsset.Succeeded())
  19.     {
  20.         SphereVisual->SetStaticMesh(SphereVisualAsset.Object);
  21.         SphereVisual->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
  22.         SphereVisual->SetWorldScale3D(FVector(0.4f));
  23.         SphereVisual->RegisterComponent();
  24.         SphereVisual->RegisterAllComponentTickFunctions(true);
  25.     }
  26.  
  27.     // ...
  28. }
  29.  
  30.  
  31. // Called when the game starts
  32. void UMySceneComponent::BeginPlay()
  33. {
  34.     Super::BeginPlay();
  35.     m_time = 0;
  36. }
  37.  
  38.  
  39. // Called every frame
  40. void UMySceneComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
  41. {
  42.     Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
  43.     m_time += DeltaTime;
  44.     this->SetRelativeLocation(FVector(sin(m_time), cos(m_time), 100) * 140);
  45.     // ...
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement