I have a C++ variable, a directional light actor pointer, that I’m setting manually in blueprints. The first operation I tried on it, from C++, is to get its rotation in the world. MyDirectionalLightActor->GetActorRotation() this produces an access violation. I’m sure that the directional light is in the world and is assigned to the C++ variable when it’s called.
Sorry- I just put MyDirectionalLightActor for the sake of clarity in the question. The pointer is SunComponent. Thats the variable that the light actor was manually assigned to in BP.
#include "Playground.h"
#include "MySkySphereClass.h"
AMySkySphereClass::AMySkySphereClass(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
}
void AMySkySphereClass::BeginPlay()
{
Super::BeginPlay();
if (MyTestDirectionalLight)
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(0, 60.0F, FColor::Black, TEXT("It's not NULL"));
}
MyTestRotator = MyTestDirectionalLight->GetActorRotation();
MyTestRotator.Pitch += 200;
MyTestDirectionalLight->SetActorRotation(MyTestRotator);
}
else
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(1, 60.0F, FColor::Black, TEXT("It's NULL"));
}
}
}
This works, since BeginPlay is called after the pointer is filled. If you would place the code into the Constructer, it wouldn’t work, because this would be called with the pointer being NULL. You would need to set the pointer in the constructor instead of the scene outliner.
You don’t need the MyTestRotator variable like i did. That was just for debugging etc.
Hi eXi. The function is being fired by a call from a box trigger begin overlap function. Simply because I wanted to see if I could send a message from gameplay events, via C++, to the skydome. The skydome is referenced in the levelscriptactor in the same way as the suncomponent is. So the event is taking place seconds after initialization. But the break seems to be happening on that line. Although, debugging toold dont always hit the exact right point, maybe?
It jumps around a bit. This has been tested separately, but, for example, the refrence to the sub-level, which inherits from the persistent level, is kept in the game mode. So (Other is the actor reference from beginoverlap);
The first bit, the overlap function, is in a class of box trigger that is sitting in the current sublevel, just as a test to send messages to the skysphere
Hey eXi- not sure what you mean by that. “debugging your code with a few ifs”. Do you work for Epic, because this a pretty incredible level of commitment! Many thanks! I’m a noob, self-taught programmer.
Haha, no, i don’t directly work for Epic, but i’m a Moderator here. The answerhub is for you guys to ask questions and we try to solve them That’s all. The Staff Guys do much more if you follow some of their answers.
But back to the problem. I mean if’s like this:
ARRDevelopGameMode* GameMode = Cast<ARRDevelopGameMode>(UGameplayStatics::GetGameMode(Other));
if(GameMode)
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(1, 60.0F, FColor::Black, TEXT("GameMode not Null"));
}
ARRSubLevelScriptActor* CurrentLevel = GameMode->GetCurrentSubLevel();
if(CurrentLevel)
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(1, 60.0F, FColor::Black, TEXT("CurrentLevel not NULL"));
}
CurrentLevel->SkySphere->UpdateSkySphere();
}
}
And so on. Just to make sure that the access violation doesn’t happen somewhere else, not related to the Sphere. Because, like i already said, i made a custom LevelScriptActor, changed the LevelBlueprint to use it and created a Sphere BP reference that i filled with the BP that we put into our scene. Than i use a TriggerBox and it’s overlap event inside the LevelBlueprint and let it call the function. This is working (despite the fact that the refresh of the material is missing, but the pitch is changing :D).
And since i have the same LevelScriptActor with the Variable and the Sphere with the Light variables and the function, the problem needs to be somewhere else. Or at least i think so
EDIT: Just a question: What is “Other” in the “GetGameMode(Other)” Parameter?
Ah ok. I did a few “if else” statements- two. And the skydome is NULL. For some reason the debugger is moving past that because the line its stopping on would be the next one.