Access instance in the level

The problem:

I have an event that is called when I choose an option in a dialog with an NPC. From there I want to access an instance in the level, a door, and open it.

http://puu.sh/cVOOF/e652849b41.png

But I am not able to get a reference to this door. First I tried to create a Actor-variable, but for some reason “Editing this value is not allowed”. I can only edit this in the defaults of an actual, spawned instance of my Dialog. But I don’t want to place instances of my dialogs in the level, but instead in C++ I am working with the defaultObject.

Next I tried if I could iterate through all door-objects and filter out the one I need by it’s name, but GetAllActorsOfClass just crashes the editor for me. And I don’t think this would be the best approach anyways for an open world game. The number of actors of some classes could get pretty high.

Long story short: How can I get a reference of my door in the level to my Dialog-blueprint without placing an instance of the dialog?

Apparently I can’t even GetPlayerCharacter in this event. It just crashes the editor. How can I work around this? There must be a way…

As I said though, calling Get All Actors Of Class in my Dialog-Blueprint crashes the editor. Could this be caused by the fact that I call the event through the DefaultObject? If so, what other options are there?

In short, you need to Get Actors of All Class and then Cast to that door blueprint in order to send an input to that door in your level. Let me know if you cant find the nodes and i’ll post a screenshot.

Alright. It seems it is really caused by the DefaultObject. I will work around this by spawning an instance beforehand. However. Can someone explain to me why this happens? So apparently the DefaultObject isn’t a normal instance. But what is it then? Why doesn’t it work like other instances do? I would love to know why this happens, so I won’t run into similar problems again :slight_smile:

Hello HammelGammel,

I see that you are having some issues. I have a few questions for you to help narrow the issue that you are experiencing.

Quick questions:

  1. Can you reproduce the crash issues in a clean project?
  2. When you say it was because of the “Default object”, could you explain what it is exactly you are referring to?
  3. How exactly were you using the “DefaultObject”?

I created a new c++ third person project and in the character’s tick-function I put this:

	UClass *test = GetClass();
	test->GetDefaultObject<ATestProjectCharacter>()->Testfunction();

Doesn’t make too much sense, but for testing-purposes it shouldn’t make a difference, if there already is an instance I could use, I assume.

This is the declaration of TestFunction()

	UFUNCTION(BlueprintImplementableEvent, Category = test)
	void Testfunction();

This is the Graph of the Character in the editor

http://puu.sh/cYMBB/71318997eb.png

starting the game results in a crash. It is caused by the GetPlayerCharacter. GetAllActorsOfClass also causes it. I assume everything refering to instances in the level somehow does. Just printing a normal string works though.

I assume I just don’t know something about the DefaultObject. It would be really helpful if someone could point out why this happens.