Code that compiles in live coding and in VS doesn't compile when I try to package the plugin

I have this line in multiple scripts:

UWpServerGlobals* ServerGlobals = GameInstance->GetSubsystem<UWpServerGlobals>();

This compiles just fine and when I run the project everything works as expected but when I try to package my plugin I am told:

 error C2059: syntax error: ')'

I mean… HUH??? This is not just a warning, this is an error and my Packaging fails because of it. How do I fix this?

Thanks in advance

Looks like a mismatch in round bracket count.
Double check your plugin source code to see if you didn’t go overzealous with closing brackets. Could be a double closing )) where a single one would suffice.

Hi Raven

That code I added to the OP was copy pasted right out of my plugin right at the place where I get this error. What is very strange though, is that I get this error EVERYWHERE in my plugin where I call GetSubsystem but when I try to fix it in ONE place, the error goes away everywhere else also…

So check this out… This is what causes me the problem

		UWpServerGlobals* globals = GetWorld()->GetGameInstance()->GetSubsystem<UWpServerGlobals>();
		if (globals)
		{
			globals->SetCookie(HeaderValue);
		}

This is how I fix it:

		//UWpServerGlobals* globals = GetWorld()->GetGameInstance()->GetSubsystem<UWpServerGlobals>();
		UWpServerGlobals* globals = GetWorld()->GetSubsystem<UWpServerGlobals>();
		if (globals)
		{
			globals->SetCookie(HeaderValue);
		}

I simply do this in one file and all other files no longer give me that problem when I hit Package… But now when I build in VS I get an error saying:

static_assert failed: 'TSubsystemClass must be derived from TBaseType'

I have no clue what to do. Even though VS now gives me an error when I hit Build, the Outpul Log shows me I have 0 errors and 0 warnings and , oh yeah, BUILD FAILED with no clue why :frowning:

Oh, and in case this is important, my subsystem is defined like so:

UCLASS()
class WORDPRESSSERVER_API UWpServerGlobals : public UGameInstanceSubsystem

Maybe not important but perhaps the problem is in the word globals?

		UWpServerGlobals* globals = GetWorld()->GetSubsystem<UWpServerGlobals>();

It could be a phrase that is already in use? This could throw off the compiler if it is already defined as a macro of some sort.

Another thing to consider

In the source of the Engine UCommonUISubsystemBase that derives from UGameInstanceSubsystem when invoking the get command the current game instance seems to be passed along as an internal parameter even though it’s class definition structure is like your subsystem.

return UGameInstance::GetSubsystem<UCommonUISubsystemBase>(GetGameInstance());

Inside of CommonUserWidget.cpp line 31:

obraz

Alternatively you can also invoke the gathering of the subsystem from the game instance

Example in an older project of mine playing around with sub-systems:


void ASubsysManager::StartSubsystem(AActor* context) {
	
	UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(context->GetWorld());
	UDevSettingSubsystem* Router = GameInstance->GetSubsystem<UDevSettingSubsystem>();
	
}

My project with subsystems compiles with zero errors.

So perhaps the error stems from the fact that you are trying to get the subsystem via UWorld instead of UGameInstance

You had it correct but for some reason you commented out the game instance variant.

1 Like

Thanks, I’ll try these other variants and see if they work.

At least you noticed the big question mark hanging over my head. When I use game instance it compiles perfectly fine for me in VS, just like it does for you… but then it gives me the ) errors when I try to package the plugin. When I use the World then the packaging process stops complaining but then I get compilation errors in VS. Totally weird.

But yeah, let me see if using gamesplaystatics or the game instance directly to get the subsystem works out any better.

Thanks for the tip!

EDIT:

Turns out this syntax works just fine for both cases:

		UGameInstance* GI = UGameplayStatics::GetGameInstance(GetWorld());
		UWpServerGlobals* SubSystem = UGameInstance::GetSubsystem<UWpServerGlobals>(GI);

I now have 0 errors or warnings both in VS and when packaging the plugin. Only issue now is that I still get BUILD FAILED but with no clue as to why :frowning: Guess I need to go read all those normal message logs and see if anything gives me a clue.

Thanks for the assist, bru. Greatly appreciated!

EDIT 2:
I found I actually have MANY errors when I try to Package my plugin. They are written in white so I didn’t notice them right away. Now that I know to look for them I am finding many errors but they are truly stupid errors to have and it makes no sense to me why I have them… Some examples:

error C2065: 'GEngine': undeclared identifier
error C2027: use of undefined type 'UGameInstance'error 
error C2027: use of undefined type 'FTimerManager'

I have to manually add #includes to Engine/World.h and even to GEngine ??? I mean… WTAF? Also,When I call GetGameInstance(GetWorld()) it says it doesn’t want a variable, it wants an expression

C2275: 'UWpServerGlobals': expected an expression instead of a type 

…but it seems happy enough if I cast UWorld to UObject… :man_shrugging: These errors make no sense!

Does the file containing UWpServerGlobals have it’s include of .generated.h as it’s last include along with core includes?

something like:

#pragma once

#include "CoreMinimal.h"
#include "WpServerGlobals.generated.h"

For the generated.h to not be underlined it will need a recompile.

Yes, it does. This is what I have in there:

#pragma once

#include "CoreMinimal.h"
#include "CML.h"
#include "CMLData.h"
#include "Engine/Texture.h"
#include "Subsystems/GameInstanceSubsystem.h"
#include "WpServerGlobals.generated.h"

The GameInstanceSubsystem include wasn’t needed for the VS build but it was needed for the Packaging

So I am not sure if I should continue this thread or not because:
A) Everything now builds/compiles/packages. Everything works now
B) But the original question still remains: Why does the Packaging process throw out errors while the build process doesn’t (and the project actually runs perfectly). Why that discrepancy?

But yeah, at least I managed to work around the original issue by using the code you suggested so even though I don’t understand why it was needed, at least my project can now be built and distributed. Would have loved to understand why this workaround was needed , though :frowning:

Do you have any editor only modules in your plugin that are not filtered in the target / build file?

These can throw a wrench in the packing process as editor only stuff like UnrealEd will trigger an error on pack. You need to then split the plugin into segments and only pack the non editor parts for the game.

Have 2 versions of the plugin one for the game and another for the editor and set different conditions in the uproject for when to load what.

I have an old project that does this, if you are still having problems with it and it could be the case then I can pack and send it to you for analysis.

No, nothing like that. :frowning:

I have 5 modules in my plugin, each module is meant to be used at runtime.

Two classes derive from UGameInstanceSubsystem
Most of them derive from UObject or UUserWidget
One of them derives from USaveGame
And the rest derives from UWpServer (one of the plugin classes which derives from UObject)

So yeah, nothing fancy

Any more in-depth information in any logs maybe?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.