diff --git a/Effects/AbstractBrushEffect.cs b/Effects/AbstractBrushEffect.cs
index 6cf43e7..fe523bc 100644
--- a/Effects/AbstractBrushEffect.cs
+++ b/Effects/AbstractBrushEffect.cs
@@ -31,6 +31,16 @@ namespace CUE.NET.Effects
/// The elapsed time (in seconds) since the last update.
public abstract void Update(float deltaTime);
+ ///
+ /// Checks if the effect can be applied to the target object.
+ ///
+ /// The this effect is attached to.
+ /// true if the effect can be attached; otherwise, false.
+ public virtual bool CanBeAppliedTo(IBrush target)
+ {
+ return true;
+ }
+
///
/// Hook which is called when the effect is attached to a device.
///
diff --git a/Effects/AbstractEffectTarget.cs b/Effects/AbstractEffectTarget.cs
index 0718d05..61cd5b5 100644
--- a/Effects/AbstractEffectTarget.cs
+++ b/Effects/AbstractEffectTarget.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using CUE.NET.Exceptions;
namespace CUE.NET.Effects
{
@@ -70,6 +71,9 @@ namespace CUE.NET.Effects
{
if (EffectTimes.Any(x => x.Effect == effect)) return;
+ if (!effect.CanBeAppliedTo(EffectTarget))
+ throw new WrapperException($"Failed to add effect.\r\nThe effect of type '{effect.GetType()}' can't be applied to the target of type '{EffectTarget.GetType()}'.");
+
effect.OnAttach(EffectTarget);
EffectTimes.Add(new EffectTimeContainer(effect, -1));
}
diff --git a/Effects/AbstractLedGroupEffect.cs b/Effects/AbstractLedGroupEffect.cs
index 35e51d0..61f3ce3 100644
--- a/Effects/AbstractLedGroupEffect.cs
+++ b/Effects/AbstractLedGroupEffect.cs
@@ -33,6 +33,16 @@ namespace CUE.NET.Effects
/// The elapsed time (in seconds) since the last update.
public abstract void Update(float deltaTime);
+ ///
+ /// Checks if the effect can be applied to the target object.
+ ///
+ /// The this effect is attached to.
+ /// true if the effect can be attached; otherwise, false.
+ public virtual bool CanBeAppliedTo(ILedGroup target)
+ {
+ return true;
+ }
+
///
/// Hook which is called when the effect is attached to a device.
///
diff --git a/Effects/IEffect.cs b/Effects/IEffect.cs
index 1e12496..8746200 100644
--- a/Effects/IEffect.cs
+++ b/Effects/IEffect.cs
@@ -38,6 +38,13 @@ namespace CUE.NET.Effects
{
#region Methods
+ ///
+ /// Checks if the effect can be applied to the target object.
+ ///
+ /// The this effect is attached to.
+ /// true if the effect can be attached; otherwise, false.
+ bool CanBeAppliedTo(T target);
+
///
/// Hook which is called when the effect is attached to a device.
///