Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Prototype pattern using templates in UE4?


I am working on thesis for my bachelor degree and I need Your help with creating the weapon system in my game. As I read a book Game Programming Patterns (by Robert Nystrom), it seemed very good idea to use prototype pattern there.

In the example in his book there are spawners that have clone() function and they clone based on the enemy prototype. As I was thinking, the idea is basically the same - I have the weapons, they have shoot() function and they clone based on the bullet prototype. Although the pattern seems clear enough, I have problem implementing it.

So the idea would be creating a weapon instance: Weapon* weapon = new Weapon(weaponsprite, bulletprototype). This is not correct code, so please don't pay attention to it.

First of all, the constructors - as I read about it, the constructors are called when I use the CreateDefaultSubobject with my class template. I created a function Init() with the arguments I need to initialize the weapon. Secondly, I wanted to make my class generic using class templates (so whatever bullet I add between the <> I could create a weapon based on that bullet type). However, as I read this is not possible aswell. One solution was to create an abstract base class for UObject (so it would be possible to use templates), but then there will be problem with overriding functions.

Maybe I miss something crucial and could do this alot easier. It would be great if you share your knowledge about this and maybe I would be able to overcome this problem.

Thank you in advance Waiting for you reply!

Product Version: UE 4.17
more ▼

asked Aug 24 '17 at 10:42 AM in C++ Programming

avatar image

129 7 11 23

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question