x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How can I Create a PlayerStart from code?

Hi,

I've deleted the PlayerStart in the UE Editor, and I would like to add one in the scene, from C++.

Here is what I've done actually (in a custom GameMode class) :

 PlayerStart = GetWorld()->SpawnActor<APlayerStart>();
 PlayerStart->SetActorLocation(Location);
 
 AddPlayerStart(PlayerStart);

The code is compiling, but when I'm starting the game, it's not using my PlayerStart but a "default" one (automatically created by the editor)..

So, how can I use mine ?

Thanks !

Product Version: Not Selected
Tags:
more ▼

asked May 01 '14 at 10:13 AM in C++ Programming

avatar image

valx76
26 6 8 13

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

try more of a full spawn code like this

 FActorSpawnParameters SpawnInfo;
 SpawnInfo.bNoCollisionFail         = true;
 SpawnInfo.Owner                 = this;
 SpawnInfo.Instigator                = NULL;
 SpawnInfo.bDeferConstruction     = false;
  
 PlayerStart = GetWorld()->SpawnActor<APlayerStart>(APlayerStart::StaticClass(), Loc ,FRotator::ZeroRotator, SpawnInfo );
more ▼

answered May 01 '14 at 04:02 PM

avatar image

Rama
10.6k 446 343 1085

avatar image valx76 May 01 '14 at 06:07 PM

Thanks for your answer (again!) Rama ! Btw there is a problem.. The PlayerStart is at the right place if I'm looking to its properties in the editor BUT the view is not at that coordinates.. In my case, I'm generating a level through code, and after, I'm creating/adding the PlayerStart, but so, not right placed.. Do you have an idea ?

(comments are locked)
10|2000 characters needed characters left

I encountered this same issue in unreal engine 4.9, but Rama's solution didn't make any difference for me.

I used the approach described here. Specifically, overriding one of AGameMode::FindPlayerStart_Implementation or AGameMode::ChoosePlayerStart_Implementation to use your APlayerStart.

In my case, I simply overid ChoosePlayerStart_Implementation() and had it return the member variable of my AGameMode-class that points to my APlayerStart instance, which is spawned as Rama describes. Making the function more robust may be advisable, but this at least appears to work.

more ▼

answered Oct 07 '15 at 02:43 AM

avatar image

ndeakin
35 5 9 9

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question