Hello,
This is narrowed and easy to reproduce version of my original problem described HERE (no need to read it to understand my problem thou). HERE IS full project.
So I create new blank project Games->Blank->use C++. Add to level single cube at location (600,600,0). Create new C++ Class that inheritance from „Pawn” class (MyPawn). Create a Blueprint based on that class. Create 2 C++ files and add it to the project in VS:
level.h:
#pragma once
#include <array>
extern std::array<std::array<int, 5>, 5> Level;
level.cpp:
#include "Level.h"
#include <array>
std::array<std::array<int, 5>, 5> Level =
{ 600,0,0,0,0,
0,600,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0};
in MyPawn.h add line:
UFUNCTION(BlueprintCallable) FVector GetPlayerStartPosition();
and in MyPawn.cpp add:
#include "Level.h"
…
FVector AMyPawn::GetPlayerStartPosition()
{
FVector start_position;
start_position.Set((float)Level[0][0], (float)Level[1][1], 0.0f);
Level[0][0] = Level[1][1] = 0;
return start_position;
}
I know Level[0][0] = 0 look kind a weird but this line is CRITICAL in my question point of view (see original post if you really wish to understand why I do that, tldr: it’s part of game logic).
Create Blueprint „MyGame” based on „Game Mode Base” in world settings select it in GameMode Override. In „MyGame” blueprint change default Pawn Class to MyPawn_BP. In MyPawn_BP „EventGrpah” from EventBeginnPlay drag line to „GetPlayerStartPosition” function and give what this function return to „SetActorLocation” New Location field as image show:
And now how this program behave (and what I don’t understand here). When you first time compile and run it everything seams to work as expected: player go to 600,600,0 position. But when you make 2 simple moves now: click „Stop” in Unreal Editor and then „Play” (notice that I don’t change anything in my code in between this 2 clicks!) actor start in … (0,0,0) location. As I say in my first post on this forum I’m a physicist not a programmer and this behavior really surprise me. Why this is happened??? Why variable Level[0][0] persist thru runs?
Best regards,
Yansen.
PS. Sorry for my poor English – it’s not my native language.