Creating TQueue Dynamically

I am having too much trouble with TQueue. I was able to solve my other issue - https://forums.unrealengine.com/deve…-to-use-tqueue with the help, but now I am stuck again.




TMap<TSubclassOf<AActor>, TQueue<AActor*>> FinalPool;

**Issue **
How can I add entries in this map? The following code gives an error

TQueue<AActor*> queue;
FinalPool.Add(‘SomeClassKey’,queue);

so I decided to make a pointer to TQueue in TMap


TMap<TSubclassOf<AActor>, TQueue<AActor*>*> FinalPool;

How Can I create TQueue using NewObject? I need to make a pointer to it.

Bump any help : (

It would appear that TQueue has a private copy constructor to prevent copying for some reason.

Blockquote
How Can I create TQueue using NewObject?

The short answer is that you don’t, TQueue does not derive from UObject so you can’t create instances using NewObject.
You could manage those allocations directly using new & delete, but that’s not really recommended. Ideally you’d probably want to use TUniquePtr, but that seems to have similar issues to TQueue.

TSharedPtr seems to work so instead of:
TMap<TSubclassOf<AActor>, TQueue<AActor*>*> FinalPool;
you’d have:
TMap<TSubclassOf<AActor>, TSharedPtr<TQueue<AActor*>>> FinalPool;
and you’d make your queue with a call to MakeShared<TQueue<AActor*>>( )

All that being said, I wouldn’t recommend this approach. There are a number of gotchas with using maps like this that leave a number of potential landmines.
I would recommend using a simpler container like TArray instead of TQueue. I have a number of maps with TArrays as values and it works great. It’s also not hard to treat an array as a queue even if it might not have the same performance profile in some cases. Which I doubt you need to worry about at this time.

1 Like

Thanks for the clarification I really hoped that Tqueue would have worked but I guess I have to stick with TArray :frowning: I hope they add more support for TQueue.