Set sprite of a spawned Paper Sprite Actor

I’m trying to make a breakout game for a school project. What i want to do is to spawn an actor from the blueprint, and then give it a sprite to show in the game. So what i’ve done is use the SpawnActor node to spawn the actor, and im trying to set its sprite. The actor is spawned in the level, but the sprite is not set.


Blueprint:


Editor View:

1 Like

After diving in to c++ code I’ve discovered that SetSprite() will succeed only if the owner is not set, or dynamic data changes are allowed, when you spawn your object it’s owner is set, so the only way for you to change sprite is make dynamic data changes allowed, I’ve dived into code deeper and I’ve discovered that AreDynamicDataChangesAllowed() will return true in several circumstances, owner must be running user construction script, or component mobility must be ether static or stationary there is a method SetMobility() that you can use to set this,
I’m working on tile map manager and my tile data is parsed from text file I can’t use tile map provided by unreal as I need more control over tiles collision and I’m using a paper sprite actors instead, when I read the data of the file I check the tile index and than I spawn object and set its sprite. my tile sprites are stationary so in the tileSprite constructor I just call GetRenderComponent()->SetMobility(EComponentMobility::Stationary); by doing this I’m allowed to set sprite after spawning it

1 Like

BTW. you can trick the engine by setting mobility to stationary setting the sprite and setting mobility to movable right after

Haven’t verified Mlody myself, but from my experience you should be able to place the SetSprite node in the construction script to get it to work. It seems really odd and I don’t fully understand it. I’m assuming that your first image is OnBeginPlay().

Yest set sprite can be placed in construction script but it will fail after you spawn the object because the owner of the object will be set and its mobility is set to movable by default, so to set sprite at run time you must set its mobility to static or stationary in order to make SetSprite() succeed

It’s all at runtime: construction, begin play, tick, whatever. When something is computed at compile time, it’s very different.

It’s the other way around: set the mobility of the sprite to Movable and then you can set it after construction during gameplay.