Hi guys, having some problems…I wanted my GameMode to hold some basic stuff from my game, like the camera and the background, so I gave it a constructor and then made a BP out of the class and set it as default game mode, but I don’t see anything being spawn in the scene…
GameMode is not available on Clients. Accessing GameMode from a Client results in an Accessed None Error.
You are adding Components to the GameMode Actor. If they are not set as a UPROPERTY with BlueprintReadWrite, you cannot see them in the Editor.
Also: If you have a camera, the Client won’t “see” this camera, because the GameMode does not exist on this client.
@Raildex_ Thanks for answering! I don’t understand the meaning of the first point, not sure what a Client is or if I am using one, but I think I am not.
I’ll post the .h as well now, but as you can see from the image below, even without BlueprintReadWrite I am able to see them inside the Editor.
My problem is that if I click play, the background sprite image and the camera are not “brought” into the level.
.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "Camera/CameraComponent.h"
#include "PaperSpriteComponent.h"
#include "BreakoutGameMode.generated.h"
/**
*
*/
UCLASS()
class BREAKOUT_API ABreakoutGameMode : public AGameModeBase
{
GENERATED_BODY()
public:
ABreakoutGameMode();
protected:
//RootComponent
USceneComponent* Dummy;
//Background
UPROPERTY(VisibleAnywhere, Category = "Game", meta = (BlueprintProtected))
UPaperSpriteComponent* Background;
//Camera
UPROPERTY(VisibleAnywhere, Category = "Game", meta = (BlueprintProtected))
UCameraComponent* Camera;
};
.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "BreakoutGameMode.h"
ABreakoutGameMode::ABreakoutGameMode():Super()
{
//RootComponent
Dummy = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
RootComponent = Dummy;
//Background
Background = CreateDefaultSubobject<UPaperSpriteComponent>(TEXT("Background"));
Background->SetWorldRotation(FRotator(0.f, 0.f, 90.f));
Background->SetupAttachment(RootComponent);
//Camera
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
Camera->SetWorldTransform(FTransform(FRotator(-90.f,0.f,0.f), FVector(0.f,0.f,1500.f)));
Camera->bAutoActivate = true;
Camera->SetupAttachment(RootComponent);
}