#ActorComponent Construction Confusion!

1 messages · Page 1 of 1 (latest)

elder glacier
#

Hey, I've created a C++ component called GuidComponent. The purpose of this component will be to have a persistent FGuid for an actor that can be used at runtime with a subsystem I'll be creating.

Currently im doing whats in the picture, on component Register, generate a new GUID if we have the default Invalid guid

However when I unload and load back into a level, all my GUIDs change.

I've tried also using:

  • OnComponentCreated
  • PostInitProperties
    But none have given the desired results</3

Is there something freaky about component creation that I'm unaware of here?

#

(did a thread bc I dont wanna interrupt sorry!)

gentle juniper
#

Is the Guid a UPROPERTY?

elder glacier
gentle juniper
#

thats odd. maybe because of the instance thing

elder glacier
#

Hmm okay, ill switch to EditAnywhere, BlueprintReadWrite to be sure and lyk, thanks for helpin out btw:)

#

Still generates a new GUID on level load unfortunately 💔

#

Interestingly, when I use PostInitProperties(with the same code as show above), every GUID is now the same and all GUIDS change to the same one again when I reboot the editor

elder glacier
#

getting desperate..... here I fuckin go experimenting again

#

one of these bastards gotta work

#

IsSelectedInEditor is disgusting to use but could work lol

#

Okay IsSelectedInEditor is const, probably for the best...

#

This give the same behaviour as PostInitProperties as I mentioned above???

mental trail
#

should probably use IsTemplate() instead of just the CDO flag

elder glacier
#

Oh nice okay! I'll give that a go when I'm back! What function would you recommend using here too?

mental trail
#

this feels more like an OnConstruction thing than registering but I'm not sure exactly... I would try to see if there are any engine examples of setting a persistent guid on an actor/comp

elder glacier
#

Nice okay, thanks for this, I'll give this a go when I'm back from work:)

sand wedge
#

onregister is fine, it will never be called on a template/archetype

#

there is also no need to manually add serialize as long as it is a uproperty it will be serialized

mental trail
#

in that case I think the simple thing is to just breakpoint who is calling the new guid

#

It feels like the IsValid check should protect against this starting in PIE as surely the property would be already present?

sand wedge
#

just make sure to test with a fresh asset, because all these manipulations with serialize could cause unexpected results

elder glacier
#

Nice thank you both! I've got a test asset, ill just nuke it and its instances to be super safe and try this all out:)

elder glacier
#

So I'm now doing this but I've also tried with using the OnRegister function, both still give me random guids when I reload the level

#

I get a bunch of breaks when placing a breakpoint at 31

#

This is with a new asset and level

elder glacier
#

So I put a breakpoint in there....

#

gif has gone freaky w the colours there but yeah this gets hit when I drag it around

#

bit hard to breakpoint and figure out why in this case 😄 Also tried to print callstacks instead of just print "hit" but that lagged me tf out

#

All seems to be duplicate of this however :

#

okay character limit fucked me there but here it is in a txt file

silver shard
#

🙀 components feels so janky and it's not helping every callback is called like 4-11 times when duplicating object. Or maybe it's just me issue and didn't find the correct way.

I tried drilling deep into this and after all of this only hope I can think of is to make the guid generation deterministic for all of those calls.
Something like grab random seed from actor guid + little something something and use that for guid generation 🤷 or just use the actor guid directly if that's suitable.

One positive about the whole thing is that actor guid seems to be fairly stable when OnRegister for example is called...