Jump to content

How to get "Actor" from an "ObjectReference"?


dagobaking

Recommended Posts

Hello.

 

I have an ObjectReference generated by using the function FindAllReferencesWithKeyword to a character in the game.

 

However, I need to have a pointer to their Actor class.

 

How do I get that from an ObjectReference?

 

I tried GetBaseObject, GetActorBase and GetLeveledActorBase (maybe incorrectly) and couldn't get it to work.

 

For reference, this is the function I'm working on:

 

Function lookAt(ObjectReference target)
   Actor a = target as Actor
   Game.SetCameraTarget(a)
EndFunction

 

Thank you.

 

ADDITIONAL INFO: I traced "a" from the above script and get "workshopnpcscript" which isn't what I expected. Is there a way to get the Actor reference I need for SetCameraTarget from that?

Edited by dagobaking
Link to comment
Share on other sites

I don't know how to check what type a reference is, unless there's a keyword for actor (in which case you can check hasKeyword on each one). But it looks like you can cast and then just check if it's null/None.

 

https://www.creationkit.com/index.php?title=Cast_Reference

 

Edit: this is assuming you're actually getting references of different types. If it's a keyword that's only on actors then the cast should always just work.

Edited by ScottyDoesKnow
Link to comment
Share on other sites

Thank you both.

 

I did some more testing by traveling out of the workshop area and running this function on other NPCs. That traced those references as "Actor". But, the result still wasn't as expected.

 

So, it looks like casting the objectreference was working. It's just that the "SetCameraTarget" function didn't do what I thought it would.

 

I expected it to aim the players first person camera toward the target.

 

It looks like it changes the camera position only in third person view. And in a kind of un-useful way...

 

Anyone know if there's a way to point the camera at another actor like I was trying to do?

Link to comment
Share on other sites

Anyone know if there's a way to point the camera at another actor like I was trying to do?

If I could figure this out, I would be a happy, happy camper. =( Seriously, I've been trying for months. I don't suppose there's any dialogue happening when that script fires? In that case it's a bit easier (though still not super reliable in my experience) to get the camera to look in certain directions.

 

I did find this post though that might help...at the end he figures out something that you might be able to put into your script?

 

https://forums.nexusmods.com/index.php?/topic/5546997-setcameratarget-does-not-work-as-expected/

 

The only other thing I can think of is digging through the base game quests and seeing if this happens at any point in the MQ? If you do find anything please let me know, as I'm also really struggling with this.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...