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 reference variable

Hello everyone! I'm started learning blueprints, and can't figure out this thing. Please explain it to me) I've got two bp - test sphere, test cube. In bp_test_cube I'm calling add Impulse, for test sphere as the target. If I'm using a cast to bp sphere, for getting sphere reference everything works fine. If I'm making variable referencing to bp_test_sphere and try to use it as a reference it doesn't work. The question is - what purpose of actor reference variables? Why when I make variable referencing to the actor, it doesn't work as a target for add impulse? What is the best way to reference one blueprint in another one?

This is working bp with cast alt text https://blueprintue.com/blueprint/no2-tvn3/

This one don't work alt textalt text https://blueprintue.com/blueprint/tcy0s7gd/

Product Version: UE 4.18
Tags:
working.png (72.3 kB)
dont-work.png (60.6 kB)
variable.png (22.1 kB)
more ▼

asked Jan 18 '18 at 12:23 PM in Blueprint Scripting

avatar image

m.a.kutuzov
17 3 3 7

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

1 answer: sort voted first

Hey there welcome to the unreal 4 community!

The reason you create Object reference is so that you don't have to cast every time you wanna reference an object.

In the situation you showed above (the one that works) on the event hit you are checking if the hit actor is a "BP_test_sphere" blueprint object. So When you hit the correct object it will let you access all the values inside that blueprint. In programming terms this is how unreal 4 handles Object oriented programming with blueprint; in other words how blueprints communicate with each other.

As for whats the best way to get an object reference?

The answer is almost right in front of you! For example use the "event begin play" node pull of that, cast to the object you want, use "get owner" as the object input. after that right click the object pin and click "promote to a variable". And voila! You now have a reference to that object.

I recommend reading through the unreal 4 documentation and/or watching some youtube videos on the subject. https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/CastNodes/ https://www.youtube.com/watch?v=HBplrWCrHtc

Here are some links and a screenshot of what i described above, I Hope this answer was somewhat helpful!

alt text Happy coding!

  • SamuelB

Edit: In the second Picture you are not checking if the Hit actor is equal to the referenced object. So you have to drag off the "hit actor" pin and check if its equal to the object. Then you branch of the boolean value from that and execute add impulse if its true. =)

objref.png (53.4 kB)
more ▼

answered Jan 18 '18 at 07:53 PM

avatar image

Samuelb
283 9 19 24

(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