I’m trying to create an EventContainer which can contain custom delegate (without specifing is it e.g. FExecuteEvent). The problem is with a proper type of it. I already tried with IDelegateInstance, TBaseDelegate and TBaseDynamicMulticastDelegate but importing them in multiple ways doesn’t work.
Currently my function looks like this:
UFUNCTION(BlueprintCallable, Category = "Event")
virtual TArray<TBaseDelegate*> GetEvents() = 0;
And the import list:
And the error:
MultiEventContainer.h(27) : Unrecognized type 'TBaseDelegate' - type must be a UCLASS, USTRUCT or UENUM
Now, is there any way to make delegate be stored as such variable?
This error means you using type that is not supported by reflection system
I dont see any use of TDelegateBase* in engine, i think it should be FDelegate and not pointer of it (reflection system can’t handle pointers other then UObjects i think), try around those
As a last resort you can remove UPROPERTY() which will remove varable from reflection system and won’t be parsed by UHT (thing that gives you error) and make nodes that operate this delegate. Removing something from reflection system also means it won’t be managed by UE4 memory management systems.
You shouldn’t be including those headers - they are correctly imported for you in Core.h, which is included by everything anyway.
There is no common base type for delegates - delegates are value types, not reference types - and so you shouldn’t think of them in terms of pointers to base classes. Just like int and float don’t have a common ‘number’ base class.
Maybe if you clarified what you are trying to do here, we could come up with a solution. You wouldn’t be able to do anything with those delegates if there was a common base class, because there’d be no common signature to execute them. That’s why you usually declare your delegate type in advance.
As says, only dynamic delegates are usable by the reflection system, so if you wanted to have a UFunction, you’d have to do something like:
class UThing : public UObject
virtual TArray<FMyEvent> GetEvents();
If you remove the UFUNCTION, you can make it a non-dynamic delegate, but the same issues with a lack of common base class remain.
Well, yes, you’re right. That was my own misconception.
I was trying to do the complex event system for my skills. The main concept was that I had an inteface called IAction and UActiveSkill implementing it. Action should have an FExecutionEvent delegate but intefaces cannot have variables so I tried to create IMultiEventContainer (with this GetEvents()). In theory I can store there (by overriding this in derived skills or actions) only one event but what if a skill contains more events? I wanted to store them all in this array and retrieve them using checkers but as you two said, there is no base class I can use.
After thinking about your comment, I’m going to delete IMultiEventContainer and I will:
- Make a IEventContainer< T > which will be storing a proper event (it will may be useful later) but only if you will be so kind to tell me how an interface can implement other interface or
- Just add GetEvent() to IAction
For additional events made in derived classes, I will simply make them in variables and execute them in server functions (simple is best…).
Great thanks for making me rethink what I have done.
Thanks for help and Steve, my misconception is explained in comments.