Im new to programing and c++ and i dont really understand how casting works, i tried to cast it to an AActor but when i pressed the play button the engine crashed
if(DirectionalLight == nullptr)
{
DirectionalLight = Cast<ADirectionalLight>(OtherActor);
}
UDirectionalLightComponent* DirLight = DirectionalLight->GetComponent();
I want to use the UDirectionalLightComponent* GetComponent() so i can get the directionalight location
#pragma once
#include "CoreMinimal.h"
#include "UObject/ObjectMacros.h"
#include "Engine/Light.h"
#include "DirectionalLight.generated.h"
class UArrowComponent;
class UDirectionalLightComponent;
/**
* Implements a directional light actor.
*/
UCLASS(ClassGroup=(Lights, DirectionalLights), MinimalAPI, meta=(ChildCanTick))
class ADirectionalLight
: public ALight
{
GENERATED_UCLASS_BODY()
#if WITH_EDITORONLY_DATA
// Reference to editor visualization arrow
private:
UPROPERTY()
TObjectPtr<UArrowComponent> ArrowComponent;
/* EditorOnly reference to the light component to allow it to be displayed in the details panel correctly */
UPROPERTY(VisibleAnywhere, Category="Light")
TObjectPtr<UDirectionalLightComponent> DirectionalLightComponent;
#endif
public:
// UObject Interface
virtual void PostLoad() override;
#if WITH_EDITOR
virtual void LoadedFromAnotherClass(const FName& OldClassName) override;
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
virtual bool CanChangeIsSpatiallyLoadedFlag() const override { return false; }
#endif
public:
#if WITH_EDITORONLY_DATA
/** Returns ArrowComponent subobject **/
ENGINE_API UArrowComponent* GetArrowComponent() const { return ArrowComponent;
}
/** Returns SkyAtmosphereComponent subobject */
ENGINE_API UDirectionalLightComponent* GetComponent() const { return DirectionalLightComponent; }
#endif
};
This is the error
LoginId:5c291f0b42d1f56caec884877f1ebd41
EpicAccountId:71603a914c784e4fae88ff22d7ff76b3
Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000000000003e0
UnrealEditor_Engine
UnrealEditor_TEST2_patch_0!AMurkat::Tick() [F:\Projects\TEST2\Source\TEST2\Murkat.cpp:66]
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Core
UnrealEditor_Core
UnrealEditor_Core
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_Engine
UnrealEditor_UnrealEd
UnrealEditor_UnrealEd
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
UnrealEditor
kernel32
ntdll