Jump to content

Can't access a prefab AnimState


Recommended Posts

I've got a pretty simple script, where I spawn a prefab, move it to where it needs to be, and then set it's light override.

    local c = SpawnPrefab("superjump_fx")
        c.Transform:SetPosition(inst.Transform:GetWorldPosition())
        c.AnimState:SetLightOverride(1)

However, although the Transform is able to be accessed without a problem, the AnimState returns as nil whenever I try to do anything with it, even outside of SetLightOverride, why is this happening?

I'd love to know as this just doesn't make sense to me, the AnimState should be accessible by everything since it's a public variable, made inside the entity's constructor, so it always exists.

Link to comment
Share on other sites

On 12/29/2021 at 9:15 AM, Leonidas IV said:

Does this prefab have AnimState? The code below must be in this prefab:


inst.entity:AddAnimState()

 

It definitely does, it's an FX prefab I made which really only serves the purpose of animating. It works correctly on it's own but I can't manipulate it outside of its own prefab file.

Link to comment
Share on other sites

On 12/30/2021 at 6:53 PM, TheSkylarr said:

It definitely does, it's an FX prefab I made which really only serves the purpose of animating. It works correctly on it's own but I can't manipulate it outside of its own prefab file.

Hmm, maybe there might be a problem importing the prefab by SpawnPrefab. Maybe the prefab is not being registered correctly? Or is the return in the prefab file incorrect?

Link to comment
Share on other sites

5 hours ago, Leonidas IV said:

Hmm, maybe there might be a problem importing the prefab by SpawnPrefab. Maybe the prefab is not being registered correctly? Or is the return in the prefab file incorrect?

This seems to happen with any prefab I spawn this way, it's very strange, I used researchlab as an example and it just doesn't work.

Link to comment
Share on other sites

I don't have any issues accessing AnimState.
Not enough details to know what's going on in your case though. 
If I had to guess, you're probably doing something weird in the prefab or you've somehow tampered with the spawning.

Edited by penguin0616
  • Like 1
Link to comment
Share on other sites

20 hours ago, penguin0616 said:

I don't have any issues accessing AnimState.
Not enough details to know what's going on in your case though. 
If I had to guess, you're probably doing something weird in the prefab or you've somehow tampered with the spawning.

Actually I think I may have the answer, since I was trying to spawn an FX prefab, AnimState didn't exist ON THE SERVER ONLY, it was only being added if the prefab was spawned on a client. Didn't consider it but I just needed to add an if not TheWorld.ismastersim before changing the AnimState.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...