x

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 can I get BP class for c++?

How can I set a BP class from my Content Browser into a variable in a c++ class? The class is for spawning an actor. Can anybody help me?

Product Version: UE 4.12
Tags:
more ▼

asked Jul 30 '16 at 10:07 AM in C++ Programming

avatar image

Panakotta00
10 1 4 8

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

1 answer: sort voted first

right click on a actor in your content browser then click on "Copy Reference" (It will copy its path)

in the class.h

 TSubclassOf<class AClass> ActorToSpawn


Class.cpp

 #include "Engine.h"
 #include "Engine/Blueprint.h"
 
 static constructorHelpers::FObjectFinder<UBlueprint> type a name for your variable here( Text("past that path here"));
 
 if (yourVariable.Succeeded())
 {
   ActorToSpawn= (UClass*)yourVariable.Object->GeneratedClass;
 }


more ▼

answered Jul 30 '16 at 11:07 AM

avatar image

saeedc
2.4k 72 42 107

avatar image Panakotta00 Jul 30 '16 at 12:54 PM

Text? -> Error

avatar image saeedc Jul 30 '16 at 01:51 PM

sorry

TEXT

avatar image Panakotta00 Jul 30 '16 at 06:32 PM

Ok, compiling works, but then i have an crash by playing

http://pastebin.com/bJawKRX6

avatar image saeedc Jul 30 '16 at 06:58 PM

Hi buddy

I don't think that the code I gave you is responsible for this crash.

will not it crash if you remove the code I gave you?

avatar image Panakotta00 Jul 31 '16 at 01:44 PM

Sorry, but when I play, and stop it, my edit will crash. When I commit all of your code out, every thing works, but with the line "static ConstructorHelpers::FObjectFinder test (TEXT("Blueprint'/Game/Test.Test'"));" the crash http://pastebin.com/02rRADUp comes by stopping playing.

avatar image Atheist91 Jul 31 '16 at 02:41 PM

The code given by saeedc cannot be used outside of class's constructor. That's exactly what the error says:

FObjectFinders can't be used outside of constructors to find Blueprint'/Game/Test.Test'

avatar image Panakotta00 Jul 31 '16 at 03:01 PM

Thank you!

avatar image Atheist91 Jul 31 '16 at 02:45 PM

I find it more convenient to expose variables like these to editor and assign them there. You still have access to it in code, but setting it up is way more flexible and user friendly. Also, it doesn't require to recompile the project each time you want to change such variable.

avatar image DomClassic Dec 14 '16 at 02:49 PM

constructorHelpers should be with a capital C ;)

(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