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"

Could I get some clarification about spawning actor classes?

I have some doubts regarding spawning an actor.

I read https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Actors/Spawning/index.html but still got a few doubts.

 World->SpawnActor<AMyProjectProjectile>(ProjectileClass, SpawnLocation, SpawnRotation);

E.g. here is a code from the 1st person shooter sample.

Here AMyProjectProjectile is the class of the actor which is spawned. What is other ProjectileClass here?

Product Version: Not Selected
Tags:
more ▼

asked Apr 22 '14 at 07:43 AM in C++ Programming

avatar image

envenger
428 77 118 148

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

2 answers: sort voted first

AMyProjectProjectile is in so called template, it makes spawnactor funtion return instance or that class insted of actor class which it does by default (withou this template). It also sets type of first argumet of that funtion so you cant place refrence of parent classes which may not be able to be casted to target classs in template.

And ProjectileClass is a refrence of class varable which conatins info of class thet needs to be spawned and is a child of AMyProjectProjectile because templated set before thet force you to. C++ does not support class refrenceing, you can't keep class type in varable, there for UObject system in engine got pseudo solution for that which is UClass class which is refrence of a class, ID card of class you could say, so classes is identified by the engine by collection of uclass objects. Thanks to that you can place class refrence in to varable or put it in funtion argument like in this case. You can get class refrence of any UObject releted class by this statment ASomeActorClass::StaticClass ()

more ▼

answered Apr 23 '14 at 05:10 AM

avatar image

Shadowriver
37.2k 936 172 1116

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

From the FPS C++ tutorial:

 UPROPERTY(EditDefaultsOnly, Category=Projectile)
 TSubclassOf<class AFPSProjectile> ProjectileClass;

If you look at the blueprint for your projectile that you will be creating, there should be a 'Projectile' section where you are able to set the class to be used. Or you can look into loading the class/blueprint in your constructor.

more ▼

answered Apr 22 '14 at 10:19 AM

avatar image

Dune
1.9k 53 40 200

avatar image envenger Apr 23 '14 at 04:02 AM

Ya i have seen that..

But my doubt is, in

     World->SpawnActor<AMyProjectProjectile>(ProjectileClass, SpawnLocation, SpawnRotation);

If ProjectileClass is the variable whose actor is spawned, then what is ?

avatar image Shadowriver Apr 23 '14 at 04:29 AM

It's a class reference (not object instance), so engine know which class of object to spawn, and as dune suggests it is a property you can set in blueprint in classes related to it where you pick which class of projectile to spawn.

avatar image envenger Apr 23 '14 at 04:49 AM

Sorry I mistyped my previous question. I mean to ask the difference between

AMyProjectProjectile

and

ProjectileClass

And which class of actor actually spawns? And why do we need to mention both of the classes.

(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