I’m adding an object at my videogame which is suposed to move around automatically inside the player view. So I created in first place a sphere and add a Tick method at my character’s class which will update sphere position. I’ve copy-pasted a code from a working project, but when I play the game, my video card driver crashes and restarts, closing the videogame window giving no time even to render first frame in it… I can’t figure out what I’m doing wrong in this case. Here it is the code:
DLLCharacter.h:
/** Updates Sphere X,Y,Z coordinates */
UFUNCTION(BlueprintCallable, Category = "Sphere")
void TickET();
/** A sphere that have to be shown in front of the camera */
UPROPERTY(VisibleDefaultsOnly, Category = Mesh)
class UStaticMeshComponent* SphereVisual;
FVector velocity;
FVector position;
DLLCharacter.cpp:
// First line at default constructor
position = FVector(250.f, 0.f, 50.f);
velocity = FVector(0.f, 0.3f, 0.1f);
//
// ... At the end of the default constructor
//
SphereVisual = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("VisualRepresentation"));
**SphereVisual->AttachParent = FirstPersonCameraComponent;**
static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere"));
if (SphereVisualAsset.Succeeded())
{
SphereVisual->SetStaticMesh(SphereVisualAsset.Object);
SphereVisual->SetRelativeLocation(position);
SphereVisual->SetWorldScale3D(FVector(0.3f));
}
void ADLLCharacter::TickET()
{
if (SphereVisual != NULL)
{
/** screen visibility borders */
if (position[1] > 250.f || position[1] < -250.f) velocity[1] = -velocity[1];
if (position[2] > 100.f || position[2] < -140.f) velocity[2] = -velocity[2];
position += velocity;
SphereVisual->SetRelativeLocation(position);
}
}
Specifications:
- Windows 7 Ultimate 64 bit SP1 (updated).
- Oculus Rift SDK 2.
- Oculus Runtime 0.5.0.1.
- Unreal 4.7.6.
- Intel core i7 4790K.
- 16 GB RAM.
- NVidia Geforce GTX 970. (drivers updated to 355.98).
If I comment the line of AttachParent, it works always. When I attach the sphere to the FirstPersonCameraComponent it crashes. I’ve already tried to attach that sphere to the character’s mesh, but same result :-S.
PS: I’m using OpenCV to process image from video inside the game and show webcam stream as dynamic texture. Anyway, it works perfectly fine without sphere attaching in 100% of the cases.
Am I crafting unproperly this object? Maybe some conflict or running out of video memory? Any tip of what I’m doing wrong??
Best regards,
maije