I have a c++ SaveGame object, but no idea how to call it in C++ or blueprints

anonymous_user_d0a34d49
Sun, 08 Nov 2015 09:20:00 +0000
Editor Scripting

I am following the tutorial on how to make a C++ SaveGame object. Everything compiles just fine, but I do not know how to actually call it. I want to learn how to call it in C++ and in blueprints. This is how I am trying to call it in blueprints http://i.imgur.com/RHwl7d9.png?1

The function I am trying to call in blueprints is SaveMeNow(). No matter what I have tried it does not allow me to actually call that specific function. I also do not know how to call it from a different C++ class because it gives me an error that says something like “illegal call of non-static member” or something. I am a newbie when it comes to C++ and any help would be much appreciated.

cppSaveGame.h

#pragma once

#include "GameFramework/SaveGame.h"
#include "cppSaveGame.generated.h"

/**
 *
 */
UCLASS()
class BP_CRASH_TEST_API UcppSaveGame : public USaveGame
{
	GENERATED_BODY()

public:

	UPROPERTY(VisibleAnywhere, Category = Basic)
		FString PlayerName;

	UPROPERTY(VisibleAnywhere, Category = Basic)
		FString SaveSlotName;

	UPROPERTY(VisibleAnywhere, Category = Basic)
		uint32 UserIndex;

		UcppSaveGame();

		UFUNCTION(BlueprintCallable, Category = "1_Custom")
		void SaveMeNow(FString newName);
};

cppSaveGame.cpp

#include "BP_crash_test.h"
#include "cppSaveGame.h"

UcppSaveGame::UcppSaveGame(){



}

void UcppSaveGame::SaveMeNow(FString newName)
{

	newName = TEXT("Default");
	PlayerName = newName;
	SaveSlotName = TEXT("Fake  name");

	UserIndex = 0;


	UcppSaveGame* SaveGameInstance = Cast<UcppSaveGame>(UGameplayStatics::CreateSaveGameObject(UcppSaveGame::StaticClass()));
	SaveGameInstance->PlayerName = newName;

	UGameplayStatics::SaveGameToSlot(SaveGameInstance, SaveGameInstance->SaveSlotName, SaveGameInstance->UserIndex);

}

5 posts - 1 participant