How to get a reference to an unspawned character?

Hi just wondering if anyone can help me. I need to get a reference to an unspawned actor so when the character is spawned the camera will target the character. Only problem is because the actor is not spawned in yet how can you get a reference to that certain character?
Any help would be greatly appreciated

Many thanks

1 Like

You can not reference something that does not exist, you need to spawn, when you spawn you get reference to new object that you should keep if you plan to communicate with it

2 Likes

You can’t references it. You need to für an Event when the actor ist spawned to Talk to your camera to target him. (blueprint communication). When your actor falls eg an Event in the camera, He can give himself AS a references Parameter to the camera, so the camera get’s it’s Position etc …

1 Like

Thanks for the help guys, i’ll give it a try

1 Like

Hey all! Saw this thread and would love some similar advice -

  • Making a hamster-wheel mobile game where obstacles spawn on a rotating landscape.
  • Player Pawn is stationary - destroying obstacles before they pass by
  • If obstacles pass by Player Pawn, a trigger box does clean up by getting obstacles to destroy themselves.

Currently I am using “Get Actor of Class” on “Actor Begin Overlap” inside both the Player Pawn and Trigger Box blueprints to determine what happens when destroying each type of the 3 obstacles that spawn.

It works, but given the slow nature of that function, is it ok to use so much if these obstacles can spawn a minimum of 0.1 seconds apart? This is my first game, so I wanna learn all the best ways to do things. Thanks so much!

1 Like

Maybe a cast should go after begin overlap?

3 obstacles are of the same parent class?

1 Like

Get actor of class is expensive. I would add “player hit” and “clean up” interfaces to your obstacles and have the clean up box or player call then as appropriate (the on overlap gives you a reference to the object that did the overlap). You can then implement different behaviours in each obstacle type for when the interface is called.

You should create a class which manages this camera system, possibly a subsystem. In your character you could call to this subsystem during event BeginPlay to register the character to the camera subsystem.

Depending on what you want to achieve, another way to make the camera aware that there is a newly spawned actor is by spawning the actor in a collision box. The actor then overlaps with the collision box which you can manage with the camera system.

** Well, this old post popped up like a recent one :slight_smile: necro time

Thanks for the reply! No - different classes. The idea is to have each of them provide different point values or do damage to the Player Pawn.

Apparently casting is pretty much the same thing because when you cast you have to provide an object reference anyway (Correct me if I’m wrong - I’m new to all this…and loving it)

EXACTLY. Your suggestion DID cross my mind - but I wasn’t sure if it was better to cast from fewer blueprints vs. have many blueprints doing various things.
So you helped segway into another question i had that doesn’t fit this thread, but oh well.

  • Do Hit events only work when physics is being simulated? I have foregone using physics because my obstacles were flying off of the rotating map even though I’m using “AttachActortoActor”. Tried teleporting the physics, didn’t help. Haven’t tried increasing the mass of the obstacles…

Thought eliminating physics would also be good for keeping things cheap. But you seem to know your stuff, and if using GetActorofClass is too expensive to repeat so often, I’ll gladly give your suggestion a try! Thanks a ton, @Light_Shock

1 Like

You could have a class ‘ItemBase’ and each child with custom functionality. So you’ll only need to cast once on begin overlap to the default itembase to know its a pickup that will give point / heal/ damage / etc.

An actor to cast against is already given if you are using collision / beginOverlap.

1 Like

You are 100% right @pezzott1 . I’ve already cleaned things up with casts as you’ve suggested - but can you tell me more about making “itemBases” - in terms of the process?
Is it like making a blueprint class and then making instances (which would be the children)?

Thank you so much for your insight. I really do appreciate it.

Instances and child classes are not the same.

I mean:

  1. Create ‘ItemBase’ (can be any name)
  • use a placeholder static mesh that floats or what not
  • have it check if player overlaps
  • if so, run X function / event that’s empty then have it destroy itself.
  1. Create a child class of ‘ItemBase’, change the static mesh and just override the function with what you want that child to do. Now you instance the child class all over your level.

So you have:

  • ItemBase (parent class)
    – HealthItem (child class)
    – ShieldItem (child class)
    – AmmoItem (child class)
    … etc

If you cast to ItemBase they will all return true… BUT there is no need to cast from within player since the item is the one that tells the player “you stepped on me, so do Xx”.

https://docs.unrealengine.com/4.27/en-US/Resources/ContentExamples/Blueprints_Advanced/2_5/

Sorry if this is too off topic :innocent:

1 Like

Can’t thank you enough @pezzott1 for that info! That is going to be incredibly useful.

Apologies for veering this thread off topic. I take full responsibility for that.

All the best, and thanks again!

2 Likes