"Get All Actors from Class" dosen't work after server travel

TArray<AActor*> actors;
UGameplayStatics::GetAllActorsOfClass(OwnerCharacter->GetWorld(), ACDrawLine::StaticClass(), actors);

	for (AActor* actor : actors)
	{
		draw = Cast<ACDrawLine>(actor);
		if (!!draw) break;
	}

I used GetAllActorsOfClass after using ServerTravel
but the array(actors) is empty.

And that code worked before using ServerTravel.
As I know “Get All Actors Of Class” can find actors which is spawned.
But I spawned actor which I want to find in editor.

That code is placed in BeginPlay and my game is Crashed when “BeginPlay” is called.

Sorry for my bad English, and thanks for reading.
If you need more information, feel free to ask. :smiley:

Have you tried setting breakpoints in Visual Studio, then attaching to the editor process?
That way you can debug this, could be a lot without more info.
Have you defined the type of line 6: “draw”?
Best to first set the breakpoints and validate that all the variables are Valid (OwnerCharacter, GetWorld(), etc…)

I tried setting breakpoints in VisualStudio, but that code has worked correctly when I started game.
after i use servertravel, and changed level. “GetAllActorsOfClass” doesn’t work and “draw” is null :frowning:

Before ServerTravel : worked
After ServerTravel : dosen’t work

Thanks for your reply :smiley:

I’d have to guess without more info though, you should start with debugging up the other functions and see where it goes wrong. GetAllActorsOfClass lives in:
“\Engine\Source\Runtime\Engine\Private\GameplayStatics.cpp” , you can put breakpoints there and read the variables. Fastest way to find these files is to use a free tool called Agent Ransack.
Also, “OwnerCharacter->GetWorld()” I think can just be “GetWorld()”

I found some problem!!
I checked map name and the map name was not what i want!!
i want map “A” but the map name i found was “Entry”.
is it related to project setting?

It’s not clear what you are trying to do and from which classes. Normally you wouldn’t do any logic on a name since a name can be edited. You’d instead set a reference to a level instead or just put your logic in a level blueprint.

  • And Entry is indeed a project setting for maps, I don’t think you’d name any of your own map classes Entry?

I solve the problem :smiley:

my parameter in ServerTravel was worng XD

that code works now :smiley:

thanks for your help