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"

How do I reference a blueprint in another blueprint (costum classes)

I wrote two C++-Classes named "SomSpell" and "SomSpellbook" deriving from AActor. Now I want the Spellbook-Blueprint to have a reference to the corresponding Spell-Blueprint.

In the Spellbook-Class I already established a variable for this:

     //The Spell that is being learned with the help of this book
         UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Defaults)
             ASomSpell* ResultingSpell;

But in the Blueprint of the Spellbook I can't choose my Spell-Blueprint. Even drag and drop doesn't work.

alt text

What am I doing wrong?

Product Version: UE 4.8
spelldrag.jpg (39.7 kB)
more ▼

asked Aug 28 '15 at 04:56 PM in C++ Programming

avatar image

431 38 48 143

avatar image Davixe Aug 28 '15 at 05:11 PM

Your Speel blueprint derives from "SomSpell"?

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

1 answer: sort voted first

Thats because there no object related to ASomSpell does not exist, you need to spawn actor first then you will be able to use it and thats only possible in runtime. So insted of using object as a varable use UClass*. UClass is class identifier and it's generated for each C++ and Blueprint class, you use it then class is needed for argumante, for example in SpawnActor. So make UClass* or:

      UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Defaults)
      TSubclassOf<ASomSpell> ResultingSpell

When you use UClass* you will have all classes in engine listed, when you use TSubclassOf which works same as UClass* (actully it's mask) editor will limit the class selection to specific class relation.

Now from that variable you can spawn specific spell selected in that varable with GetWorld->SpawnActor(ResultingSpell) and returning value store in some spell array or whatever in spell book (??? don't know what system you exacly making :p)

more ▼

answered Aug 28 '15 at 06:40 PM

avatar image

37.8k 937 172 1123

avatar image Pseudocorpus Aug 30 '15 at 02:19 PM

Thanks Shadowriver! The Subclass-thing works great. :) I am storing the spawned spell in an array inside the character-class.

Is there a possibility to check if the spell has been learned before I even start learn the book? In this case I have to check the

 TArray<ASomSpell*> LearnedSpells

of the already spawned spells against the

 TSubclassOf<ASomSpell> ResultingSpell

inside the Spellbook class. The following code doesn't work:

 for (int32 iSpellList = 0; iSpellList < LearnedSpells.Num(); iSpellList++)
             if (LearnedSpells[iSpellList] == SpellbookItem->ResultingSpell)
                 PrintNotifyMessage(NSLOCTEXT("StruggleOfMages", "SpellAlreadyLearned", "I already know that spell"));
                 return false;

Thanks again!

avatar image Shadowriver Aug 30 '15 at 02:43 PM

UClass is not the same as object spawned from that class, do you can't compare those 2. There function in UObject for that called IsA


So do:


You need to remeber that this function also checks the base classes, so if you input ASomSpelit will always return true in your loop. If you use some spells as a base for other spells you should not use this as it will give you erroneous results. To check if object is really of specific class not any other, you use GetClass() and compire it with some UClass*, like this:

 if(LearnedSpells[iSpellList].GetClass() == SpellbookItem->ResultingSpell)
avatar image Pseudocorpus Aug 30 '15 at 08:21 PM

Once again, Shadowriver saves the day. That works like a charm, thanks!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
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