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 set up a reference to a static level object in a dynamically instantiated actor?

I have a fixed, static object in my level placed in the editor that I want my player-controlled pawns to be able to reference in their C++ code. I would like to set up that reference in the editor.

It doesn't seem possible to set up those references by deriving the pawn class in BP and setting the object reference as the default value. They just stay as None despite being highlighted when attempting to drag the object to the slot.

So how can I do that without fragile logic like finding the object by name?

Product Version: UE 4.16
Tags:
more ▼

asked Jun 11 '17 at 10:53 AM in C++ Programming

avatar image

mechkg
17 4 6 11

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

1 answer: sort voted first

Well, if you know that the actor is a singleton, the usual way to do it is to create a public, static function in the singleton object's class which uses an actor iterator to look for an object of its own class and return itself. (See here: https://wiki.unrealengine.com/Iterators:_Object_%26_Actor_Iterators,_Optional_Class_Scope_For_Faster_Search#Actor_Iterator) You'll need to pass it a world so it knows where to look, though.

Does this thing have to be an actor, though? There are better ways of doing this in most cases, like with a game singleton. That's a better way to ensure the object exists without adding magic stuff your level designers need to add to every level just to get them to work.

more ▼

answered Jun 12 '17 at 10:19 PM

avatar image

Teiwaz
629 26 29 55

avatar image mechkg Jun 13 '17 at 10:29 AM

I totally agree that it doesn't seem like a great way, but how else would you do that if every level is supposed to have a certain special object (like an exit door for instance) and the level is invalid if it does not have it?

(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