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 to properly spawn child actor?

Hey guys! I'm wondering what is the correct way to spawn actor of child class and get pointer to parent class.

.h

     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gun)
         class TSubclassOf<class ABaseWeapon> gunClass;
 
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gun)
         class ABaseWeapon * gun;


And here is .cpp

     const FVector spawnLocation = GetMesh()->GetSocketLocation("RightHand");
     const FRotator spawnRotation = GetMesh()->GetSocketRotation("RightHand");
     const FActorSpawnParameters spawnParams;
     gun = GetWorld()->SpawnActor<ABaseWeapon>(gunClass, spawnLocation, spawnRotation, spawnParams);


But I'm still getting exceptions. Any help?

Product Version: UE 4.17
Tags:
more ▼

asked Sep 21 '17 at 03:51 PM in C++ Programming

avatar image

VenomSolo
1 1 2 1

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

2 answers: sort voted first

What are the exceptions?

Is the ABaseWeapon header file included anywhere?

Also try

 TSubclassOf<ABaseWeapon> gunClass;

  • Without the class defines at the start.

more ▼

answered Sep 21 '17 at 04:04 PM

avatar image

Dune
1.9k 53 40 200

avatar image VenomSolo Sep 21 '17 at 04:17 PM

I get exception 0xC0000005: access violation in:

     template< class T >
         T* SpawnActor( UClass* Class, FVector const& Location, FRotator const& Rotation, const FActorSpawnParameters& SpawnParameters = FActorSpawnParameters() )
         {
             return CastChecked<T>(SpawnActor(Class, &Location, &Rotation, SpawnParameters),ECastCheckedType::NullAllowed);
         }


Header file is included.

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

First thing I would try is checking GetWorld is not returning nullptr. Probably worth checking that on gunClass too.,

more ▼

answered Dec 21 '17 at 12:22 PM

avatar image

LemmyRamone
1 1

(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