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"

Object class cast to Actor class always fails, why?

alt text

I have a blueprint with parent class Actor (BombComponent in the attached image). I can get its Class object with a Get Class call, but it returns an Object Class. I want to cast this to an Actor Class so I can use that with a SpawnActor node to spawn it (SpawnActor only accepts Actor Class, not Object Class).

This cast always fails. What am I misunderstanding?

Product Version: Not Selected
Tags:
cast.jpg (71.1 kB)
more ▼

asked Jan 24 '15 at 10:29 PM in Blueprint Scripting

avatar image

mindsoup
15 3 4 7

avatar image Furroy Jan 25 '15 at 03:24 PM

The issue is with how you're getting the class, not the cast itself. I found a hokey work around, I don't understand what's wrong with using "Get Class" node, but there's a "Select Class" node I just configured to always return the A value.

alt text

cast_actor.png (127.3 kB)
avatar image mindsoup Jan 25 '15 at 03:37 PM

I can find a Select node (wildcards) and a Select Object node but not Select Class. Where can I find the Select Class node?

avatar image Furroy Jan 25 '15 at 03:41 PM

Hmmm.. what version of the engine are you using? Perhaps it was recently added.

avatar image mindsoup Jan 25 '15 at 03:42 PM

I'm using engine 4.6.1

avatar image Furroy Jan 25 '15 at 03:43 PM

I have 4.7 preview 4, so perhaps it is brand new?

avatar image mindsoup Jan 25 '15 at 03:43 PM

Ah maybe! Perhaps this problem will be solved in 4.7 (can't update atm since I'm not subscribed).

avatar image Furroy Jan 25 '15 at 03:49 PM

Yea, I don't see what's wrong with using GetClass the way you are doing it, but every example I've found of GetClass always has an input, not selecting the class in the dropdown. Perhaps that is a bug.

avatar image nopunintendo Jan 26 '15 at 01:33 AM

I'm fairly certain that the Select node changes output type depending on what you connect it to. Try laying down a regular Select node and then plugging the output into a Class type input.

You can also right click the output of the Select node and click "Change Pin Type" if it's not connected to anything.

(comments are locked)
10|2000 characters needed characters left

3 answers: sort voted first

When you "Spawn Actor", are you able to select the blueprint in the drop down?

Narg

more ▼

answered Jan 25 '15 at 02:29 PM

avatar image

Narghile
1.7k 74 38 109

avatar image mindsoup Jan 25 '15 at 02:36 PM

alt text

Yes I am. When I select the BP in the SpawnActor node, everything spawns fine. However, I wish to be able to dynamically select an actor class to spawn, instead of hardcoding it into the SpawnActor node, which has lead to my current dilemma.

cast2.jpg (38.6 kB)
avatar image Ockertvs Jan 25 '15 at 11:57 PM

"Dynamically select an actor class to spawn" , do you mean in-game during runtime ?If you can provide me with a little more information on what exactly it is you are trying to accomplish I might be able to provide you with a solution.Hope to hear from you. Best Regards, Ockert.

avatar image mindsoup Jan 26 '15 at 12:10 AM

My project is basically to re-create this bomb defusing game (simply as a study project to get my feet wet in UE4/VR), where a bomb has a number of components that each need to be disabled in order to defuse the bomb before the timer runs out. Each component is effectively a mini puzzle, and exists as a 3d model (actor) in the scene.

So, I'm making a bunch (right now I think I have 6 planned) of different components. These are blueprints that inherit from my Bomb Component blueprint, which inherits from Actor (see the picture in my initial question). I'm currently working on the system that randomly selects and spawns X amount of these components, depending on the difficulty setting (more difficult = more components).

Since the SpawnActor node requires an Actor Class object to determine what to spawn (see the 2nd picture, just above this post), I figured I could make an array of Actor Class objects (so not Actor Objects) that contain all of the components, and during runtime randomly select from that array to pick the component to spawn. This means every time the bomb has a random/different set of components, which should improve replayability.

However, it appears the only way in UE4 to get a reference to the Actor Class is with the Get Class node (picture 1), which returns an Object Class and not an Actor Class. The SpawnActor node requires an Actor Class and that is why I need to be able to cast Object Class to Actor Class - so I can get a reference to my blueprint to dynamically spawn a randomly chosen component into my scene at runtime.

Furroy pointed out above that it seems Get Class isn't working as one would expect but doesn't know why, and it might also be that UE 4.7 has an additional mechanic to obtain a Class reference. I'm still on 4.6.1 though.

(comments are locked)
10|2000 characters needed characters left

Thanks for the detailed explanation , before I saw your reply I created a basic example of a "spawn system" which is not "hard coded" as you described above.Which I will post , hopefully you find it interesting ,its not a "how-to" but more just a basic explanation , as there is almost always more than one way of doing something , depending on your needs.I'm not sure how experienced you are with Blueprint Scripting , so forgive me If my explanation is too/less informative. I'll read you're explanation through another time and see If I can provide you with an additional solution/explanation. System created was tested and works as expected. Just another important question.You are referring to components of "A Bomb"(yours in this case) and not components in Blueprints that makes up a Blueprint right? Hope this sheds a little more light.

alt text

my_example.jpg (607.7 kB)
more ▼

answered Jan 26 '15 at 01:05 AM

avatar image

Ockertvs
158 6 10 23

avatar image Ockertvs Jan 26 '15 at 01:35 AM

Reading through your explanation again , is occurs to me (might be wrong) , you want to "get" your Bomb Component(which is a parent actor) but you want to spawn (child components) of the parent(BombComponent) ?

avatar image mindsoup Jan 26 '15 at 07:41 AM

Right now I'm just using BombComponent since it's a dummy component rather than one of it's children. For the spawning it shouldn't matter.

Anyway, thanks for the reply, I'll look into it :)

(comments are locked)
10|2000 characters needed characters left

I ran into the same issue, and ended up needing to just create a temporary variable for the Actor Class I wanted to select and using a Set node with the drop down selected, instead of the drop down on the Get Class node. Ultimately simpler from a blueprint point of view anyway, since it reduces the number of nodes (no casting required).

Looks like @Ockertvs used a similar solution, although he's just using a true/false branch instead of a Switch To (+ Enum in my case) node to select from a larger list of Actor Classes.

more ▼

answered May 26 '17 at 02:24 AM

avatar image

Xandemon
1 3 1

(comments are locked)
10|2000 characters needed characters left
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