Hello everyone,
I am literally trying now for 4 days to do one easy thing: Spawning an Actor into the world when the level begins, only by using c++.
The main reason for this might be that I don’t even understand where I should enter the code for this. I am working with Java, Java for Android, PHP etc. for several years but it doesn’t help at all.
Now my question:
When I create a default c++ vehicle project several cpp + h files are going to be created. There are also some C# files.
- What do the C# files like: Map1.Build.cs, Map1.Target.cs, Map1Editor.Target.cs ? Are they for compiling or do they call the c++ files in a way?
- Where is the entering point when the game starts within the c++ or C# files? For instance, Java has a main() - ok. I got files like: Map1.cpp, Map1GameMode.cpp, Map1Hud.cpp, Map1Pawn.cpp etc. (default c++ vehicle project). Where do I put my new cpp code which is then being executed when pressing the “play”-button?
- If it might be the case that my basic c++ knowledge is the problem, then please just tell me where to start. I watched several hours of tutorials which ended up using blueprints or drag and drop new actors into the world. I read parts of the documentation but I couldn’t find anything.
Example issue:
I created a new Actor c++ class and h file which looks like this:
// Fill out your copyright notice in the Description page of Project Settings.
#include "StreetActor1.h"
#include "Runtime/Engine/Classes/Engine/World.h"
// Sets default values
AStreetActor1::AStreetActor1()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AStreetActor1::BeginPlay()
{
Super::BeginPlay();
FVector Location(0.0f, 0.0f, 0.0f);
FRotator Rotation(0.0f, 0.0f, 0.0f);
UWorld *world = GetWorld();
FActorSpawnParameters SpawnInfo;
world->SpawnActor<AStreetActor1>(Location, Rotation, SpawnInfo);
}
// Called every frame
void AStreetActor1::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "StreetActor1.generated.h"
UCLASS()
class MAP1_API AStreetActor1 : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AStreetActor1();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};
I know there is now Mesh or Material attached to, so nothing will spawn. However, in the world outliner the actor should be there. Of course, the actor won’t get created because there is no class call like “AStreetActor1->BeginPlay()”. Where do I put this class call into? Into the Map1.cpp?
I hope you understand what I am asking for. I did everything now to find the issue and I am asking myself if I am just to stupid to find the issue. I already commented on the last post of this question and it didn’t help. How to spawn actor in C++? Been trying for 9 hours now - C++ - Epic Developer Community Forums
Thank you for reading and I hope you have an idea of solving my confusion