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 attach a camera component to a actor at runtime?

Hi guys,

I'd like to know how to attach a camera component to a actor dynamically. I know I can attach one using PCIP in the constructor, but can I attach a camera component at runtime outside the constructor? I think I need to register it after I attach it? Also, How to set the new attached camera as the main camera?

P.S. I think I don't need to load a camera asset in this situation, but if I want to attach a mesh or something, how to load the asset at runtime?

Thank you!

Product Version: Not Selected
Tags:
more ▼

asked Jul 15 '14 at 02:03 PM in C++ Programming

avatar image

Yinjunxu
11 3 4 7

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

1 answer: sort voted first

https://answers.unrealengine.com/questions/24952/wisdom-request-disembodied-static-scene-camera-in.html - setting camera.

https://docs.unrealengine.com/latest/INT/Programming/Assets/AsyncLoading/index.html - loading asset at run-time.

To attach actor/component to another actor/component you should call AActor::AttachRootComponent or USceneComponent::AttachTo

more ▼

answered Jul 15 '14 at 02:14 PM

avatar image

BiggestSmile
1.6k 52 36 103

avatar image Yinjunxu Jul 15 '14 at 02:52 PM

Thank you for your reply. I think before using USceneComponent::AttachTo, I need to create component first, such as PCIP.CreateDefaultSubobject. It seems this PCIP.CreateDefaultSubobject function can only be called in the constructor. Is there any function that I can use to create components outside constructor?

avatar image BiggestSmile Jul 15 '14 at 03:35 PM

Components are meant to be created only in constructor.

What are you trying to achieve exactly? Components must be initialized in constructor; game would crash or show error(not sure what exactly, forgot :( ) if one of your subobjects is not initialized.

Just initialize all your components inside constructor, then, when required, simply call YourCamera->AttachTo(RootComponent) for example. There are various attaching functions available.

(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