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"

Creating a simple object in UE4 C++ code does not work

Hey guys, I cant seem to make create a simple object in ue4 c++. I have these two different classes: RandomGenActor.h - > UClass of AActor RandomGenActor.cpp

and another CarClass.h -> is just a blank class CarClass.cpp

And what I want to do is to create an object of CarClass inside RandomGenActor, here's what I want to do: to declare

 CarClass * CarC = new CarClass;

inside RoomGenActor

but I'm getting compilation errors, any idea what is the proper way to do this? Thanks!

Product Version: UE 4.12
Tags:
more ▼

asked Sep 11 '16 at 10:12 AM in C++ Programming

avatar image

Jibera
51 8 11 14

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

2 answers: sort voted first

While that's the typical C++ way of creating a new object, you want to use UWorld::SpawnActor so that it registers your object in the engine properly.

Here's a reference: https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Actors/Spawning/

more ▼

answered Sep 11 '16 at 08:20 PM

avatar image

Mastersmith98
286 10 4 11

avatar image Jibera Sep 12 '16 at 02:48 AM

Does it really have to be an actor? Is there no other way? I've come across this post but the method that I tried here doesnt work, I havent tried constructing the object like the second method mentioned here yet. https://answers.unrealengine.com/questions/110369/how-to-create-a-simple-object-in-c-with-ue4.html

avatar image KevinDrure Sep 12 '16 at 12:23 PM

Make your class inheriting UObject and use the NewObject() method to create your derived UObject.

https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Objects/Creation/

avatar image Jibera Sep 12 '16 at 02:19 PM

oh okay, I'll try that. Anyways, is it also okay if I just code all objects in different classes and just have them communicate in a blueprint if thats possible?

avatar image Mastersmith98 Sep 13 '16 at 06:18 PM

Yeah that's possible, you can create blueprint_implementable functions in your class and expose all the member variables to blueprints, but it might be more work than it's worth, depending on what you're trying to accomplish.

avatar image Jibera Sep 14 '16 at 12:41 PM

I'm trying to implement a certain algorithm. What method would you recommend? Thank you

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

I do this. I just declare it (my custom class) as an instance variable as part of my AActor derived class and I don't have the compile issues. However it is problematic if the actor gets re-used or serialised from some reason.

more ▼

answered Sep 14 '16 at 07:50 AM

avatar image

funkinessfactor
58 1 9

avatar image Jibera Sep 14 '16 at 12:32 PM

Can you show me how you did it? 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