Skip to content

Add Blueprint Restriction Validator#21

Open
KaosSpectrum wants to merge 1 commit into
Flassari:mainfrom
KaosSpectrum:main
Open

Add Blueprint Restriction Validator#21
KaosSpectrum wants to merge 1 commit into
Flassari:mainfrom
KaosSpectrum:main

Conversation

@KaosSpectrum

Copy link
Copy Markdown
Contributor

This validator can be used to restrict functions/event overrides and implementation in blueprint classes.

image image

Usage

  1. Create a validator by deriving from UEditorValidator_BlueprintRestriction.

  2. Override AppliesTo() to restrict which assets the validator should scan.

  3. Override BuildNodeRules() to block Blueprint events, overrides, or custom node patterns.

  4. Override BuildCallRules() to block calls to specific functions.

Example:

virtual void BuildNodeRules(TArray<FEditorValidatorBlueprintNodeRule>& OutRules) const override
{
	OutRules.Add(
		FORBID_OVERRIDE(TEXT("ReceiveTick"))
			.Message(TEXT("Blueprint Tick is not allowed."))
			.Suggest(TEXT("Use a timer or native C++ update path instead."))
			.Warning()
	);
	
	OutRules.Add(
		FORBID_OVERRIDE(TEXT("K2_ActivateAbility"))
			.When([](const UBlueprint* Blueprint)
			{
				return Blueprint
					&& Blueprint->GeneratedClass
					&& Blueprint->GeneratedClass->IsChildOf(
						UMyActionGameplayAbility::StaticClass());
			})
			.Message(TEXT("Do not override ActivateAbility directly in UMyActionGameplayAbility."))
			.Suggest(TEXT("Move gameplay logic into OnActionStarted instead."))
			.Error()
	);
}

virtual void BuildCallRules(TArray<FEditorValidatorBlueprintCallRule>& OutRules) const override
{
	OutRules.Add(
		FORBID_CALL(UGameplayStatics::StaticClass(), TEXT("GetAllActorsOfClass"))
			.Message(TEXT("GetAllActorsOfClass is not allowed in this Blueprint."))
			.Suggest(TEXT("Use a cached registry or subsystem lookup instead."))
			.PerformanceWarning()
	);
	
		OutRules.Add(
			FORBID_CALL(UGameplayStatics::StaticClass(), TEXT("PlaySound2D"))
				.When([](const UBlueprint* Blueprint)
				{
					return Blueprint
						&& Blueprint->GeneratedClass
						&& !Blueprint->GeneratedClass->IsChildOf(UUserWidget::StaticClass());
				})
				.Message(TEXT("PlaySound2D is only allowed from UI widgets. Gameplay Blueprints must route audio through the project audio subsystem."))
				.Suggest(TEXT("Use UGameAudioSubsystem::PlaySfx or an approved audio event wrapper instead."))
				.Error()
);
}

Also there is a limited BP version using developer settings for node override/implementation restrictions.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant