I am trying to enable physics simulation on the Capsule Component of one of my actors in it’s constructor. However setting it there doesnt seem to actually enable physics. The only place I’ve gotten it to work is in BeginPlay (or any other function after BeginPlay is called).
Is there a reason this doesnt work?
I would like to do this in the constructor because I cant seem to set constraints on the Capsule Collision’s body instance until after physics has been enabled.
Creating a new blueprint derived from my C++ class works, which is not something I want to do every time I modify my constructor.
However I could not get it to work by cleaning and then building my solution. I also tried running ‘Refresh Visual Studio Project’ (Is this what you meant by ‘generate new vs project files’?) which also did not update the blueprint with the new constructor. Is there something I’m doing wrong?
This should normally work look at the 2d example project or even the 3rd person project they set it all up in constructor. the reason I can think of is when you derive a blueprint from your c++ class and you add code to c++ constructor later, even if you compile your code your blueprint won’t be updated you have to delete it and create new blueprint class, or just simply clean build your solution and/or generate new vs project files
nah its just the way it is just remember to either set everything in constructor before you create blueprint, or set it in constructor and than set it in blueprint again but yeah you’re right it may be troublesome to recreate blueprint specially like a level blueprint I usually set only default values in c++ and the rest is set in blueprint but if it happens that I change some components etc. than the only way to deal with it is to recreate blueprint or you can add new stuff in to blueprint itself to avoid it
After some more tests, I found that adding a new component to the Actor (and then removing that component) will also update the blueprint with a new constructor without needing to entirely recreate the blueprint.
This may work for other things like Levels if you add a new UPROPERTY to the class, though I have not tested this.
Finally figured out what the problem really is and how to fix it.
The problem is that the ‘Simulate Physics’ property and ‘Enable Gravity’ properties, when set in the constructor act as the default for a newly created blueprint based off of the object created with those properties set. If you change the property values after you’ve created the blueprint, the blueprint will still have the saved values for ‘Simulate Physics’ and ‘Enable Gravity’. So no matter how many times you compile, they will still be those original values.
The above however is normal behavior for the Unreal Engine. The actual problem is that those properties are not visible in the blueprint IF the component’s UPROPERTY is set to EditAnywhere.
The ‘Simulate Physics’ and ‘Enable Gravity’ properties are however visible if you set the component’s UPROPERTY to VisibleAnywhere.
Below are what you see in the blueprint editor if your component is set to EditAnywhere and VisibleAnywhere respectively.
It is a little unintuitive that an EditAnywhere property would have fewer configurable parameters than VisibleAnywhere. Maybe worthy of a bug report?